<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><link rel="stylesheet" type="text/css" href="style.css" /><script type="text/javascript" src="highlight.js"></script></head><body><pre><span class="hs-comment">{-
(c) The University of Glasgow 2006
(c) The AQUA Project, Glasgow University, 1994-1998


Core-syntax unfoldings

Unfoldings (which can travel across module boundaries) are in Core
syntax (namely @CoreExpr@s).

The type @Unfolding@ sits ``above'' simply-Core-expressions
unfoldings, capturing ``higher-level'' things we know about a binding,
usually things that the simplifier found out (e.g., ``it's a
literal'').  In the corner of a @CoreUnfolding@ unfolding, you will
find, unsurprisingly, a Core expression.
-}</span><span>
</span><span id="line-17"></span><span>
</span><span id="line-18"></span><span class="hs-pragma">{-# LANGUAGE CPP #-}</span><span>
</span><span id="line-19"></span><span>
</span><span id="line-20"></span><span class="hs-pragma">{-# OPTIONS_GHC -Wno-incomplete-record-updates #-}</span><span>
</span><span id="line-21"></span><span>
</span><span id="line-22"></span><span class="hs-keyword">module</span><span> </span><span class="hs-identifier">GHC.Core.Unfold</span><span> </span><span class="hs-special">(</span><span>
</span><span id="line-23"></span><span>        </span><span class="annot"><a href="GHC.Core.html#Unfolding"><span class="hs-identifier">Unfolding</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Core.html#UnfoldingGuidance"><span class="hs-identifier">UnfoldingGuidance</span></a></span><span class="hs-special">,</span><span>   </span><span class="hs-comment">-- Abstract types</span><span>
</span><span id="line-24"></span><span>
</span><span id="line-25"></span><span>        </span><span class="annot"><a href="GHC.Core.html#noUnfolding"><span class="hs-identifier">noUnfolding</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-26"></span><span>        </span><span class="annot"><a href="GHC.Core.Unfold.html#mkUnfolding"><span class="hs-identifier">mkUnfolding</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Core.Unfold.html#mkCoreUnfolding"><span class="hs-identifier">mkCoreUnfolding</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-27"></span><span>        </span><span class="annot"><a href="GHC.Core.Unfold.html#mkFinalUnfolding"><span class="hs-identifier">mkFinalUnfolding</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Core.Unfold.html#mkSimpleUnfolding"><span class="hs-identifier">mkSimpleUnfolding</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Core.Unfold.html#mkWorkerUnfolding"><span class="hs-identifier">mkWorkerUnfolding</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-28"></span><span>        </span><span class="annot"><a href="GHC.Core.Unfold.html#mkInlineUnfolding"><span class="hs-identifier">mkInlineUnfolding</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Core.Unfold.html#mkInlineUnfoldingWithArity"><span class="hs-identifier">mkInlineUnfoldingWithArity</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-29"></span><span>        </span><span class="annot"><a href="GHC.Core.Unfold.html#mkInlinableUnfolding"><span class="hs-identifier">mkInlinableUnfolding</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Core.Unfold.html#mkWwInlineRule"><span class="hs-identifier">mkWwInlineRule</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-30"></span><span>        </span><span class="annot"><a href="GHC.Core.Unfold.html#mkCompulsoryUnfolding"><span class="hs-identifier">mkCompulsoryUnfolding</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Core.Unfold.html#mkDFunUnfolding"><span class="hs-identifier">mkDFunUnfolding</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-31"></span><span>        </span><span class="annot"><a href="GHC.Core.Unfold.html#specUnfolding"><span class="hs-identifier">specUnfolding</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-32"></span><span>
</span><span id="line-33"></span><span>        </span><span class="annot"><a href="GHC.Core.Unfold.html#ArgSummary"><span class="hs-identifier">ArgSummary</span></a></span><span class="hs-special">(</span><span class="hs-glyph">..</span><span class="hs-special">)</span><span class="hs-special">,</span><span>
</span><span id="line-34"></span><span>
</span><span id="line-35"></span><span>        </span><span class="annot"><a href="GHC.Core.Unfold.html#couldBeSmallEnoughToInline"><span class="hs-identifier">couldBeSmallEnoughToInline</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Core.Unfold.html#inlineBoringOk"><span class="hs-identifier">inlineBoringOk</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-36"></span><span>        </span><span class="annot"><a href="GHC.Core.Unfold.html#certainlyWillInline"><span class="hs-identifier">certainlyWillInline</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Core.Unfold.html#smallEnoughToInline"><span class="hs-identifier">smallEnoughToInline</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-37"></span><span>
</span><span id="line-38"></span><span>        </span><span class="annot"><a href="GHC.Core.Unfold.html#callSiteInline"><span class="hs-identifier">callSiteInline</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Core.Unfold.html#CallCtxt"><span class="hs-identifier">CallCtxt</span></a></span><span class="hs-special">(</span><span class="hs-glyph">..</span><span class="hs-special">)</span><span class="hs-special">,</span><span>
</span><span id="line-39"></span><span>
</span><span id="line-40"></span><span>        </span><span class="hs-comment">-- Reexport from GHC.Core.Subst (it only live there so it can be used</span><span>
</span><span id="line-41"></span><span>        </span><span class="hs-comment">-- by the Very Simple Optimiser)</span><span>
</span><span id="line-42"></span><span>        </span><span class="annot"><a href="GHC.Core.SimpleOpt.html#exprIsConApp_maybe"><span class="hs-identifier">exprIsConApp_maybe</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Core.SimpleOpt.html#exprIsLiteral_maybe"><span class="hs-identifier">exprIsLiteral_maybe</span></a></span><span>
</span><span id="line-43"></span><span>    </span><span class="hs-special">)</span><span> </span><span class="hs-keyword">where</span><span class="hs-cpp">

#include &quot;HsVersions.h&quot;
</span><span>
</span><span id="line-47"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Prelude.html"><span class="hs-identifier">GHC.Prelude</span></a></span><span>
</span><span id="line-48"></span><span>
</span><span id="line-49"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Driver.Session.html"><span class="hs-identifier">GHC.Driver.Session</span></a></span><span>
</span><span id="line-50"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Core.html"><span class="hs-identifier">GHC.Core</span></a></span><span>
</span><span id="line-51"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Core.Opt.OccurAnal.html"><span class="hs-identifier">GHC.Core.Opt.OccurAnal</span></a></span><span> </span><span class="hs-special">(</span><span> </span><span class="annot"><a href="GHC.Core.Opt.OccurAnal.html#occurAnalyseExpr"><span class="hs-identifier">occurAnalyseExpr</span></a></span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-52"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Core.SimpleOpt.html"><span class="hs-identifier">GHC.Core.SimpleOpt</span></a></span><span>
</span><span id="line-53"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Core.Opt.Arity.html"><span class="hs-identifier">GHC.Core.Opt.Arity</span></a></span><span>   </span><span class="hs-special">(</span><span> </span><span class="annot"><a href="GHC.Core.Opt.Arity.html#manifestArity"><span class="hs-identifier">manifestArity</span></a></span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-54"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Core.Utils.html"><span class="hs-identifier">GHC.Core.Utils</span></a></span><span>
</span><span id="line-55"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Types.Id.html"><span class="hs-identifier">GHC.Types.Id</span></a></span><span>
</span><span id="line-56"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Types.Demand.html"><span class="hs-identifier">GHC.Types.Demand</span></a></span><span> </span><span class="hs-special">(</span><span> </span><span class="annot"><a href="GHC.Types.Demand.html#StrictSig"><span class="hs-identifier">StrictSig</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Types.Demand.html#isDeadEndSig"><span class="hs-identifier">isDeadEndSig</span></a></span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-57"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Core.DataCon.html"><span class="hs-identifier">GHC.Core.DataCon</span></a></span><span>
</span><span id="line-58"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Types.Literal.html"><span class="hs-identifier">GHC.Types.Literal</span></a></span><span>
</span><span id="line-59"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Builtin.PrimOps.html"><span class="hs-identifier">GHC.Builtin.PrimOps</span></a></span><span>
</span><span id="line-60"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Types.Id.Info.html"><span class="hs-identifier">GHC.Types.Id.Info</span></a></span><span>
</span><span id="line-61"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Types.Basic.html"><span class="hs-identifier">GHC.Types.Basic</span></a></span><span>  </span><span class="hs-special">(</span><span> </span><span class="annot"><a href="GHC.Types.Basic.html#Arity"><span class="hs-identifier">Arity</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Types.Basic.html#InlineSpec"><span class="hs-identifier">InlineSpec</span></a></span><span class="hs-special">(</span><span class="hs-glyph">..</span><span class="hs-special">)</span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Types.Basic.html#inlinePragmaSpec"><span class="hs-identifier">inlinePragmaSpec</span></a></span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-62"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Core.Type.html"><span class="hs-identifier">GHC.Core.Type</span></a></span><span>
</span><span id="line-63"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Builtin.Names.html"><span class="hs-identifier">GHC.Builtin.Names</span></a></span><span>
</span><span id="line-64"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Builtin.Types.Prim.html"><span class="hs-identifier">GHC.Builtin.Types.Prim</span></a></span><span> </span><span class="hs-special">(</span><span> </span><span class="annot"><a href="GHC.Builtin.Types.Prim.html#realWorldStatePrimTy"><span class="hs-identifier">realWorldStatePrimTy</span></a></span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-65"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Data.Bag.html"><span class="hs-identifier">GHC.Data.Bag</span></a></span><span>
</span><span id="line-66"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Utils.Misc.html"><span class="hs-identifier">GHC.Utils.Misc</span></a></span><span>
</span><span id="line-67"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Utils.Outputable.html"><span class="hs-identifier">GHC.Utils.Outputable</span></a></span><span>
</span><span id="line-68"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Types.ForeignCall.html"><span class="hs-identifier">GHC.Types.ForeignCall</span></a></span><span>
</span><span id="line-69"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Types.Name.html"><span class="hs-identifier">GHC.Types.Name</span></a></span><span>
</span><span id="line-70"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Utils.Error.html"><span class="hs-identifier">GHC.Utils.Error</span></a></span><span>
</span><span id="line-71"></span><span>
</span><span id="line-72"></span><span class="hs-keyword">import</span><span> </span><span class="hs-keyword">qualified</span><span> </span><span class="annot"><a href="../../bytestring/src/Data.ByteString.html#"><span class="hs-identifier">Data.ByteString</span></a></span><span> </span><span class="hs-keyword">as</span><span> </span><span class="annot"><span class="hs-identifier">BS</span></span><span>
</span><span id="line-73"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="../../base/src/Data.List.html#"><span class="hs-identifier">Data.List</span></a></span><span>
</span><span id="line-74"></span><span>
</span><span id="line-75"></span><span class="hs-comment">{-
************************************************************************
*                                                                      *
\subsection{Making unfoldings}
*                                                                      *
************************************************************************
-}</span><span>
</span><span id="line-82"></span><span>
</span><span id="line-83"></span><span class="annot"><a href="GHC.Core.Unfold.html#mkFinalUnfolding"><span class="hs-identifier hs-type">mkFinalUnfolding</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Driver.Session.html#DynFlags"><span class="hs-identifier hs-type">DynFlags</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.html#UnfoldingSource"><span class="hs-identifier hs-type">UnfoldingSource</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Types.Demand.html#StrictSig"><span class="hs-identifier hs-type">StrictSig</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.html#CoreExpr"><span class="hs-identifier hs-type">CoreExpr</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.html#Unfolding"><span class="hs-identifier hs-type">Unfolding</span></a></span><span>
</span><span id="line-84"></span><span class="hs-comment">-- &quot;Final&quot; in the sense that this is a GlobalId that will not be further</span><span>
</span><span id="line-85"></span><span class="hs-comment">-- simplified; so the unfolding should be occurrence-analysed</span><span>
</span><span id="line-86"></span><span id="mkFinalUnfolding"><span class="annot"><span class="annottext">mkFinalUnfolding :: DynFlags -&gt; UnfoldingSource -&gt; StrictSig -&gt; CoreArg -&gt; Unfolding
</span><a href="GHC.Core.Unfold.html#mkFinalUnfolding"><span class="hs-identifier hs-var hs-var">mkFinalUnfolding</span></a></span></span><span> </span><span id="local-6989586621680863981"><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680863981"><span class="hs-identifier hs-var">dflags</span></a></span></span><span> </span><span id="local-6989586621680863980"><span class="annot"><span class="annottext">UnfoldingSource
</span><a href="#local-6989586621680863980"><span class="hs-identifier hs-var">src</span></a></span></span><span> </span><span id="local-6989586621680863979"><span class="annot"><span class="annottext">StrictSig
</span><a href="#local-6989586621680863979"><span class="hs-identifier hs-var">strict_sig</span></a></span></span><span> </span><span id="local-6989586621680863978"><span class="annot"><span class="annottext">CoreArg
</span><a href="#local-6989586621680863978"><span class="hs-identifier hs-var">expr</span></a></span></span><span>
</span><span id="line-87"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">DynFlags -&gt; UnfoldingSource -&gt; Bool -&gt; Bool -&gt; CoreArg -&gt; Unfolding
</span><a href="GHC.Core.Unfold.html#mkUnfolding"><span class="hs-identifier hs-var">mkUnfolding</span></a></span><span> </span><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680863981"><span class="hs-identifier hs-var">dflags</span></a></span><span> </span><span class="annot"><span class="annottext">UnfoldingSource
</span><a href="#local-6989586621680863980"><span class="hs-identifier hs-var">src</span></a></span><span>
</span><span id="line-88"></span><span>                </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">True</span></span><span> </span><span class="hs-comment">{- Top level -}</span><span>
</span><span id="line-89"></span><span>                </span><span class="hs-special">(</span><span class="annot"><span class="annottext">StrictSig -&gt; Bool
</span><a href="GHC.Types.Demand.html#isDeadEndSig"><span class="hs-identifier hs-var">isDeadEndSig</span></a></span><span> </span><span class="annot"><span class="annottext">StrictSig
</span><a href="#local-6989586621680863979"><span class="hs-identifier hs-var">strict_sig</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-90"></span><span>                </span><span class="annot"><span class="annottext">CoreArg
</span><a href="#local-6989586621680863978"><span class="hs-identifier hs-var">expr</span></a></span><span>
</span><span id="line-91"></span><span>
</span><span id="line-92"></span><span class="annot"><a href="GHC.Core.Unfold.html#mkCompulsoryUnfolding"><span class="hs-identifier hs-type">mkCompulsoryUnfolding</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.html#CoreExpr"><span class="hs-identifier hs-type">CoreExpr</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.html#Unfolding"><span class="hs-identifier hs-type">Unfolding</span></a></span><span>
</span><span id="line-93"></span><span id="mkCompulsoryUnfolding"><span class="annot"><span class="annottext">mkCompulsoryUnfolding :: CoreArg -&gt; Unfolding
</span><a href="GHC.Core.Unfold.html#mkCompulsoryUnfolding"><span class="hs-identifier hs-var hs-var">mkCompulsoryUnfolding</span></a></span></span><span> </span><span id="local-6989586621680863977"><span class="annot"><span class="annottext">CoreArg
</span><a href="#local-6989586621680863977"><span class="hs-identifier hs-var">expr</span></a></span></span><span>         </span><span class="hs-comment">-- Used for things that absolutely must be unfolded</span><span>
</span><span id="line-94"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">UnfoldingSource
-&gt; Bool -&gt; CoreArg -&gt; UnfoldingGuidance -&gt; Unfolding
</span><a href="GHC.Core.Unfold.html#mkCoreUnfolding"><span class="hs-identifier hs-var">mkCoreUnfolding</span></a></span><span> </span><span class="annot"><span class="annottext">UnfoldingSource
</span><a href="GHC.Core.html#InlineCompulsory"><span class="hs-identifier hs-var">InlineCompulsory</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">True</span></span><span>
</span><span id="line-95"></span><span>                    </span><span class="hs-special">(</span><span class="annot"><span class="annottext">HasDebugCallStack =&gt; DynFlags -&gt; CoreArg -&gt; CoreArg
DynFlags -&gt; CoreArg -&gt; CoreArg
</span><a href="GHC.Core.SimpleOpt.html#simpleOptExpr"><span class="hs-identifier hs-var">simpleOptExpr</span></a></span><span> </span><span class="annot"><span class="annottext">DynFlags
</span><a href="GHC.Driver.Session.html#unsafeGlobalDynFlags"><span class="hs-identifier hs-var">unsafeGlobalDynFlags</span></a></span><span> </span><span class="annot"><span class="annottext">CoreArg
</span><a href="#local-6989586621680863977"><span class="hs-identifier hs-var">expr</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-96"></span><span>                    </span><span class="hs-special">(</span><span class="annot"><span class="annottext">UnfWhen :: Int -&gt; Bool -&gt; Bool -&gt; UnfoldingGuidance
</span><a href="GHC.Core.html#UnfWhen"><span class="hs-identifier hs-type">UnfWhen</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">ug_arity :: Int
</span><a href="GHC.Core.html#ug_arity"><span class="hs-identifier hs-var">ug_arity</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">0</span></span><span>    </span><span class="hs-comment">-- Arity of unfolding doesn't matter</span><span>
</span><span id="line-97"></span><span>                             </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">ug_unsat_ok :: Bool
</span><a href="GHC.Core.html#ug_unsat_ok"><span class="hs-identifier hs-var">ug_unsat_ok</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="GHC.Core.html#unSaturatedOk"><span class="hs-identifier hs-var">unSaturatedOk</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">ug_boring_ok :: Bool
</span><a href="GHC.Core.html#ug_boring_ok"><span class="hs-identifier hs-var">ug_boring_ok</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="GHC.Core.html#boringCxtOk"><span class="hs-identifier hs-var">boringCxtOk</span></a></span><span> </span><span class="hs-special">}</span><span class="hs-special">)</span><span>
</span><span id="line-98"></span><span>
</span><span id="line-99"></span><span>
</span><span id="line-100"></span><span class="hs-comment">-- Note [Top-level flag on inline rules]</span><span>
</span><span id="line-101"></span><span class="hs-comment">-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~</span><span>
</span><span id="line-102"></span><span class="hs-comment">-- Slight hack: note that mk_inline_rules conservatively sets the</span><span>
</span><span id="line-103"></span><span class="hs-comment">-- top-level flag to True.  It gets set more accurately by the simplifier</span><span>
</span><span id="line-104"></span><span class="hs-comment">-- Simplify.simplUnfolding.</span><span>
</span><span id="line-105"></span><span>
</span><span id="line-106"></span><span class="annot"><a href="GHC.Core.Unfold.html#mkSimpleUnfolding"><span class="hs-identifier hs-type">mkSimpleUnfolding</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Driver.Session.html#DynFlags"><span class="hs-identifier hs-type">DynFlags</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.html#CoreExpr"><span class="hs-identifier hs-type">CoreExpr</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.html#Unfolding"><span class="hs-identifier hs-type">Unfolding</span></a></span><span>
</span><span id="line-107"></span><span id="mkSimpleUnfolding"><span class="annot"><span class="annottext">mkSimpleUnfolding :: DynFlags -&gt; CoreArg -&gt; Unfolding
</span><a href="GHC.Core.Unfold.html#mkSimpleUnfolding"><span class="hs-identifier hs-var hs-var">mkSimpleUnfolding</span></a></span></span><span> </span><span id="local-6989586621680863967"><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680863967"><span class="hs-identifier hs-var">dflags</span></a></span></span><span> </span><span id="local-6989586621680863966"><span class="annot"><span class="annottext">CoreArg
</span><a href="#local-6989586621680863966"><span class="hs-identifier hs-var">rhs</span></a></span></span><span>
</span><span id="line-108"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">DynFlags -&gt; UnfoldingSource -&gt; Bool -&gt; Bool -&gt; CoreArg -&gt; Unfolding
</span><a href="GHC.Core.Unfold.html#mkUnfolding"><span class="hs-identifier hs-var">mkUnfolding</span></a></span><span> </span><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680863967"><span class="hs-identifier hs-var">dflags</span></a></span><span> </span><span class="annot"><span class="annottext">UnfoldingSource
</span><a href="GHC.Core.html#InlineRhs"><span class="hs-identifier hs-var">InlineRhs</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">False</span></span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">False</span></span><span> </span><span class="annot"><span class="annottext">CoreArg
</span><a href="#local-6989586621680863966"><span class="hs-identifier hs-var">rhs</span></a></span><span>
</span><span id="line-109"></span><span>
</span><span id="line-110"></span><span class="annot"><a href="GHC.Core.Unfold.html#mkDFunUnfolding"><span class="hs-identifier hs-type">mkDFunUnfolding</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Types.Var.html#Var"><span class="hs-identifier hs-type">Var</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.DataCon.html#DataCon"><span class="hs-identifier hs-type">DataCon</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.html#CoreExpr"><span class="hs-identifier hs-type">CoreExpr</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.html#Unfolding"><span class="hs-identifier hs-type">Unfolding</span></a></span><span>
</span><span id="line-111"></span><span id="mkDFunUnfolding"><span class="annot"><span class="annottext">mkDFunUnfolding :: [Id] -&gt; DataCon -&gt; [CoreArg] -&gt; Unfolding
</span><a href="GHC.Core.Unfold.html#mkDFunUnfolding"><span class="hs-identifier hs-var hs-var">mkDFunUnfolding</span></a></span></span><span> </span><span id="local-6989586621680863963"><span class="annot"><span class="annottext">[Id]
</span><a href="#local-6989586621680863963"><span class="hs-identifier hs-var">bndrs</span></a></span></span><span> </span><span id="local-6989586621680863962"><span class="annot"><span class="annottext">DataCon
</span><a href="#local-6989586621680863962"><span class="hs-identifier hs-var">con</span></a></span></span><span> </span><span id="local-6989586621680863961"><span class="annot"><span class="annottext">[CoreArg]
</span><a href="#local-6989586621680863961"><span class="hs-identifier hs-var">ops</span></a></span></span><span>
</span><span id="line-112"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">DFunUnfolding :: [Id] -&gt; DataCon -&gt; [CoreArg] -&gt; Unfolding
</span><a href="GHC.Core.html#DFunUnfolding"><span class="hs-identifier hs-type">DFunUnfolding</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">df_bndrs :: [Id]
</span><a href="GHC.Core.html#df_bndrs"><span class="hs-identifier hs-var">df_bndrs</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[Id]
</span><a href="#local-6989586621680863963"><span class="hs-identifier hs-var">bndrs</span></a></span><span>
</span><span id="line-113"></span><span>                  </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">df_con :: DataCon
</span><a href="GHC.Core.html#df_con"><span class="hs-identifier hs-var">df_con</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">DataCon
</span><a href="#local-6989586621680863962"><span class="hs-identifier hs-var">con</span></a></span><span>
</span><span id="line-114"></span><span>                  </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">df_args :: [CoreArg]
</span><a href="GHC.Core.html#df_args"><span class="hs-identifier hs-var">df_args</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(CoreArg -&gt; CoreArg) -&gt; [CoreArg] -&gt; [CoreArg]
forall a b. (a -&gt; b) -&gt; [a] -&gt; [b]
</span><a href="../../base/src/GHC.Base.html#map"><span class="hs-identifier hs-var">map</span></a></span><span> </span><span class="annot"><span class="annottext">CoreArg -&gt; CoreArg
</span><a href="GHC.Core.Opt.OccurAnal.html#occurAnalyseExpr"><span class="hs-identifier hs-var">occurAnalyseExpr</span></a></span><span> </span><span class="annot"><span class="annottext">[CoreArg]
</span><a href="#local-6989586621680863961"><span class="hs-identifier hs-var">ops</span></a></span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-115"></span><span>                  </span><span class="hs-comment">-- See Note [Occurrence analysis of unfoldings]</span><span>
</span><span id="line-116"></span><span>
</span><span id="line-117"></span><span class="annot"><a href="GHC.Core.Unfold.html#mkWwInlineRule"><span class="hs-identifier hs-type">mkWwInlineRule</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Driver.Session.html#DynFlags"><span class="hs-identifier hs-type">DynFlags</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.html#CoreExpr"><span class="hs-identifier hs-type">CoreExpr</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Types.Basic.html#Arity"><span class="hs-identifier hs-type">Arity</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.html#Unfolding"><span class="hs-identifier hs-type">Unfolding</span></a></span><span>
</span><span id="line-118"></span><span id="mkWwInlineRule"><span class="annot"><span class="annottext">mkWwInlineRule :: DynFlags -&gt; CoreArg -&gt; Int -&gt; Unfolding
</span><a href="GHC.Core.Unfold.html#mkWwInlineRule"><span class="hs-identifier hs-var hs-var">mkWwInlineRule</span></a></span></span><span> </span><span id="local-6989586621680863956"><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680863956"><span class="hs-identifier hs-var">dflags</span></a></span></span><span> </span><span id="local-6989586621680863955"><span class="annot"><span class="annottext">CoreArg
</span><a href="#local-6989586621680863955"><span class="hs-identifier hs-var">expr</span></a></span></span><span> </span><span id="local-6989586621680863954"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863954"><span class="hs-identifier hs-var">arity</span></a></span></span><span>
</span><span id="line-119"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">UnfoldingSource
-&gt; Bool -&gt; CoreArg -&gt; UnfoldingGuidance -&gt; Unfolding
</span><a href="GHC.Core.Unfold.html#mkCoreUnfolding"><span class="hs-identifier hs-var">mkCoreUnfolding</span></a></span><span> </span><span class="annot"><span class="annottext">UnfoldingSource
</span><a href="GHC.Core.html#InlineStable"><span class="hs-identifier hs-var">InlineStable</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">True</span></span><span>
</span><span id="line-120"></span><span>                   </span><span class="hs-special">(</span><span class="annot"><span class="annottext">HasDebugCallStack =&gt; DynFlags -&gt; CoreArg -&gt; CoreArg
DynFlags -&gt; CoreArg -&gt; CoreArg
</span><a href="GHC.Core.SimpleOpt.html#simpleOptExpr"><span class="hs-identifier hs-var">simpleOptExpr</span></a></span><span> </span><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680863956"><span class="hs-identifier hs-var">dflags</span></a></span><span> </span><span class="annot"><span class="annottext">CoreArg
</span><a href="#local-6989586621680863955"><span class="hs-identifier hs-var">expr</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-121"></span><span>                   </span><span class="hs-special">(</span><span class="annot"><span class="annottext">UnfWhen :: Int -&gt; Bool -&gt; Bool -&gt; UnfoldingGuidance
</span><a href="GHC.Core.html#UnfWhen"><span class="hs-identifier hs-type">UnfWhen</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">ug_arity :: Int
</span><a href="GHC.Core.html#ug_arity"><span class="hs-identifier hs-var">ug_arity</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863954"><span class="hs-identifier hs-var">arity</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">ug_unsat_ok :: Bool
</span><a href="GHC.Core.html#ug_unsat_ok"><span class="hs-identifier hs-var">ug_unsat_ok</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="GHC.Core.html#unSaturatedOk"><span class="hs-identifier hs-var">unSaturatedOk</span></a></span><span>
</span><span id="line-122"></span><span>                            </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">ug_boring_ok :: Bool
</span><a href="GHC.Core.html#ug_boring_ok"><span class="hs-identifier hs-var">ug_boring_ok</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="GHC.Core.html#boringCxtNotOk"><span class="hs-identifier hs-var">boringCxtNotOk</span></a></span><span> </span><span class="hs-special">}</span><span class="hs-special">)</span><span>
</span><span id="line-123"></span><span>
</span><span id="line-124"></span><span class="annot"><a href="GHC.Core.Unfold.html#mkWorkerUnfolding"><span class="hs-identifier hs-type">mkWorkerUnfolding</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Driver.Session.html#DynFlags"><span class="hs-identifier hs-type">DynFlags</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#CoreExpr"><span class="hs-identifier hs-type">CoreExpr</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.html#CoreExpr"><span class="hs-identifier hs-type">CoreExpr</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.html#Unfolding"><span class="hs-identifier hs-type">Unfolding</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.html#Unfolding"><span class="hs-identifier hs-type">Unfolding</span></a></span><span>
</span><span id="line-125"></span><span class="hs-comment">-- See Note [Worker-wrapper for INLINABLE functions] in GHC.Core.Opt.WorkWrap</span><span>
</span><span id="line-126"></span><span id="mkWorkerUnfolding"><span class="annot"><span class="annottext">mkWorkerUnfolding :: DynFlags -&gt; (CoreArg -&gt; CoreArg) -&gt; Unfolding -&gt; Unfolding
</span><a href="GHC.Core.Unfold.html#mkWorkerUnfolding"><span class="hs-identifier hs-var hs-var">mkWorkerUnfolding</span></a></span></span><span> </span><span id="local-6989586621680863951"><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680863951"><span class="hs-identifier hs-var">dflags</span></a></span></span><span> </span><span id="local-6989586621680863950"><span class="annot"><span class="annottext">CoreArg -&gt; CoreArg
</span><a href="#local-6989586621680863950"><span class="hs-identifier hs-var">work_fn</span></a></span></span><span>
</span><span id="line-127"></span><span>                  </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#CoreUnfolding"><span class="hs-identifier hs-type">CoreUnfolding</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">uf_src :: Unfolding -&gt; UnfoldingSource
</span><a href="GHC.Core.html#uf_src"><span class="hs-identifier hs-var">uf_src</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680863947"><span class="annot"><span class="annottext">UnfoldingSource
</span><a href="#local-6989586621680863947"><span class="hs-identifier hs-var">src</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">uf_tmpl :: Unfolding -&gt; CoreArg
</span><a href="GHC.Core.html#uf_tmpl"><span class="hs-identifier hs-var">uf_tmpl</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680863945"><span class="annot"><span class="annottext">CoreArg
</span><a href="#local-6989586621680863945"><span class="hs-identifier hs-var">tmpl</span></a></span></span><span>
</span><span id="line-128"></span><span>                                 </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">uf_is_top :: Unfolding -&gt; Bool
</span><a href="GHC.Core.html#uf_is_top"><span class="hs-identifier hs-var">uf_is_top</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680863943"><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621680863943"><span class="hs-identifier hs-var">top_lvl</span></a></span></span><span> </span><span class="hs-special">}</span><span class="hs-special">)</span><span>
</span><span id="line-129"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">UnfoldingSource -&gt; Bool
</span><a href="GHC.Core.html#isStableSource"><span class="hs-identifier hs-var">isStableSource</span></a></span><span> </span><span class="annot"><span class="annottext">UnfoldingSource
</span><a href="#local-6989586621680863947"><span class="hs-identifier hs-var">src</span></a></span><span>
</span><span id="line-130"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">UnfoldingSource
-&gt; Bool -&gt; CoreArg -&gt; UnfoldingGuidance -&gt; Unfolding
</span><a href="GHC.Core.Unfold.html#mkCoreUnfolding"><span class="hs-identifier hs-var">mkCoreUnfolding</span></a></span><span> </span><span class="annot"><span class="annottext">UnfoldingSource
</span><a href="#local-6989586621680863947"><span class="hs-identifier hs-var">src</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621680863943"><span class="hs-identifier hs-var">top_lvl</span></a></span><span> </span><span class="annot"><span class="annottext">CoreArg
</span><a href="#local-6989586621680863941"><span class="hs-identifier hs-var">new_tmpl</span></a></span><span> </span><span class="annot"><span class="annottext">UnfoldingGuidance
</span><a href="#local-6989586621680863940"><span class="hs-identifier hs-var">guidance</span></a></span><span>
</span><span id="line-131"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-132"></span><span>    </span><span id="local-6989586621680863941"><span class="annot"><span class="annottext">new_tmpl :: CoreArg
</span><a href="#local-6989586621680863941"><span class="hs-identifier hs-var hs-var">new_tmpl</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">HasDebugCallStack =&gt; DynFlags -&gt; CoreArg -&gt; CoreArg
DynFlags -&gt; CoreArg -&gt; CoreArg
</span><a href="GHC.Core.SimpleOpt.html#simpleOptExpr"><span class="hs-identifier hs-var">simpleOptExpr</span></a></span><span> </span><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680863951"><span class="hs-identifier hs-var">dflags</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">CoreArg -&gt; CoreArg
</span><a href="#local-6989586621680863950"><span class="hs-identifier hs-var">work_fn</span></a></span><span> </span><span class="annot"><span class="annottext">CoreArg
</span><a href="#local-6989586621680863945"><span class="hs-identifier hs-var">tmpl</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-133"></span><span>    </span><span id="local-6989586621680863940"><span class="annot"><span class="annottext">guidance :: UnfoldingGuidance
</span><a href="#local-6989586621680863940"><span class="hs-identifier hs-var hs-var">guidance</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">DynFlags -&gt; Bool -&gt; CoreArg -&gt; UnfoldingGuidance
</span><a href="GHC.Core.Unfold.html#calcUnfoldingGuidance"><span class="hs-identifier hs-var">calcUnfoldingGuidance</span></a></span><span> </span><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680863951"><span class="hs-identifier hs-var">dflags</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">False</span></span><span> </span><span class="annot"><span class="annottext">CoreArg
</span><a href="#local-6989586621680863941"><span class="hs-identifier hs-var">new_tmpl</span></a></span><span>
</span><span id="line-134"></span><span>
</span><span id="line-135"></span><span class="annot"><a href="GHC.Core.Unfold.html#mkWorkerUnfolding"><span class="hs-identifier hs-var">mkWorkerUnfolding</span></a></span><span> </span><span class="annot"><span class="annottext">DynFlags
</span><span class="hs-identifier">_</span></span><span> </span><span class="annot"><span class="annottext">CoreArg -&gt; CoreArg
</span><span class="hs-identifier">_</span></span><span> </span><span class="annot"><span class="annottext">Unfolding
</span><span class="hs-identifier">_</span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Unfolding
</span><a href="GHC.Core.html#noUnfolding"><span class="hs-identifier hs-var">noUnfolding</span></a></span><span>
</span><span id="line-136"></span><span>
</span><span id="line-137"></span><span class="hs-comment">-- | Make an unfolding that may be used unsaturated</span><span>
</span><span id="line-138"></span><span class="hs-comment">-- (ug_unsat_ok = unSaturatedOk) and that is reported as having its</span><span>
</span><span id="line-139"></span><span class="hs-comment">-- manifest arity (the number of outer lambdas applications will</span><span>
</span><span id="line-140"></span><span class="hs-comment">-- resolve before doing any work).</span><span>
</span><span id="line-141"></span><span class="annot"><a href="GHC.Core.Unfold.html#mkInlineUnfolding"><span class="hs-identifier hs-type">mkInlineUnfolding</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.html#CoreExpr"><span class="hs-identifier hs-type">CoreExpr</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.html#Unfolding"><span class="hs-identifier hs-type">Unfolding</span></a></span><span>
</span><span id="line-142"></span><span id="mkInlineUnfolding"><span class="annot"><span class="annottext">mkInlineUnfolding :: CoreArg -&gt; Unfolding
</span><a href="GHC.Core.Unfold.html#mkInlineUnfolding"><span class="hs-identifier hs-var hs-var">mkInlineUnfolding</span></a></span></span><span> </span><span id="local-6989586621680863937"><span class="annot"><span class="annottext">CoreArg
</span><a href="#local-6989586621680863937"><span class="hs-identifier hs-var">expr</span></a></span></span><span>
</span><span id="line-143"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">UnfoldingSource
-&gt; Bool -&gt; CoreArg -&gt; UnfoldingGuidance -&gt; Unfolding
</span><a href="GHC.Core.Unfold.html#mkCoreUnfolding"><span class="hs-identifier hs-var">mkCoreUnfolding</span></a></span><span> </span><span class="annot"><span class="annottext">UnfoldingSource
</span><a href="GHC.Core.html#InlineStable"><span class="hs-identifier hs-var">InlineStable</span></a></span><span>
</span><span id="line-144"></span><span>                    </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">True</span></span><span>         </span><span class="hs-comment">-- Note [Top-level flag on inline rules]</span><span>
</span><span id="line-145"></span><span>                    </span><span class="annot"><span class="annottext">CoreArg
</span><a href="#local-6989586621680863936"><span class="hs-identifier hs-var">expr'</span></a></span><span> </span><span class="annot"><span class="annottext">UnfoldingGuidance
</span><a href="#local-6989586621680863935"><span class="hs-identifier hs-var">guide</span></a></span><span>
</span><span id="line-146"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-147"></span><span>    </span><span id="local-6989586621680863936"><span class="annot"><span class="annottext">expr' :: CoreArg
</span><a href="#local-6989586621680863936"><span class="hs-identifier hs-var hs-var">expr'</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">HasDebugCallStack =&gt; DynFlags -&gt; CoreArg -&gt; CoreArg
DynFlags -&gt; CoreArg -&gt; CoreArg
</span><a href="GHC.Core.SimpleOpt.html#simpleOptExpr"><span class="hs-identifier hs-var">simpleOptExpr</span></a></span><span> </span><span class="annot"><span class="annottext">DynFlags
</span><a href="GHC.Driver.Session.html#unsafeGlobalDynFlags"><span class="hs-identifier hs-var">unsafeGlobalDynFlags</span></a></span><span> </span><span class="annot"><span class="annottext">CoreArg
</span><a href="#local-6989586621680863937"><span class="hs-identifier hs-var">expr</span></a></span><span>
</span><span id="line-148"></span><span>    </span><span id="local-6989586621680863935"><span class="annot"><span class="annottext">guide :: UnfoldingGuidance
</span><a href="#local-6989586621680863935"><span class="hs-identifier hs-var hs-var">guide</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">UnfWhen :: Int -&gt; Bool -&gt; Bool -&gt; UnfoldingGuidance
</span><a href="GHC.Core.html#UnfWhen"><span class="hs-identifier hs-type">UnfWhen</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">ug_arity :: Int
</span><a href="GHC.Core.html#ug_arity"><span class="hs-identifier hs-var">ug_arity</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">CoreArg -&gt; Int
</span><a href="GHC.Core.Opt.Arity.html#manifestArity"><span class="hs-identifier hs-var">manifestArity</span></a></span><span> </span><span class="annot"><span class="annottext">CoreArg
</span><a href="#local-6989586621680863936"><span class="hs-identifier hs-var">expr'</span></a></span><span>
</span><span id="line-149"></span><span>                    </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">ug_unsat_ok :: Bool
</span><a href="GHC.Core.html#ug_unsat_ok"><span class="hs-identifier hs-var">ug_unsat_ok</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="GHC.Core.html#unSaturatedOk"><span class="hs-identifier hs-var">unSaturatedOk</span></a></span><span>
</span><span id="line-150"></span><span>                    </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">ug_boring_ok :: Bool
</span><a href="GHC.Core.html#ug_boring_ok"><span class="hs-identifier hs-var">ug_boring_ok</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621680863933"><span class="hs-identifier hs-var">boring_ok</span></a></span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-151"></span><span>    </span><span id="local-6989586621680863933"><span class="annot"><span class="annottext">boring_ok :: Bool
</span><a href="#local-6989586621680863933"><span class="hs-identifier hs-var hs-var">boring_ok</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">CoreArg -&gt; Bool
</span><a href="GHC.Core.Unfold.html#inlineBoringOk"><span class="hs-identifier hs-var">inlineBoringOk</span></a></span><span> </span><span class="annot"><span class="annottext">CoreArg
</span><a href="#local-6989586621680863936"><span class="hs-identifier hs-var">expr'</span></a></span><span>
</span><span id="line-152"></span><span>
</span><span id="line-153"></span><span class="hs-comment">-- | Make an unfolding that will be used once the RHS has been saturated</span><span>
</span><span id="line-154"></span><span class="hs-comment">-- to the given arity.</span><span>
</span><span id="line-155"></span><span class="annot"><a href="GHC.Core.Unfold.html#mkInlineUnfoldingWithArity"><span class="hs-identifier hs-type">mkInlineUnfoldingWithArity</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Types.Basic.html#Arity"><span class="hs-identifier hs-type">Arity</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.html#CoreExpr"><span class="hs-identifier hs-type">CoreExpr</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.html#Unfolding"><span class="hs-identifier hs-type">Unfolding</span></a></span><span>
</span><span id="line-156"></span><span id="mkInlineUnfoldingWithArity"><span class="annot"><span class="annottext">mkInlineUnfoldingWithArity :: Int -&gt; CoreArg -&gt; Unfolding
</span><a href="GHC.Core.Unfold.html#mkInlineUnfoldingWithArity"><span class="hs-identifier hs-var hs-var">mkInlineUnfoldingWithArity</span></a></span></span><span> </span><span id="local-6989586621680863932"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863932"><span class="hs-identifier hs-var">arity</span></a></span></span><span> </span><span id="local-6989586621680863931"><span class="annot"><span class="annottext">CoreArg
</span><a href="#local-6989586621680863931"><span class="hs-identifier hs-var">expr</span></a></span></span><span>
</span><span id="line-157"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">UnfoldingSource
-&gt; Bool -&gt; CoreArg -&gt; UnfoldingGuidance -&gt; Unfolding
</span><a href="GHC.Core.Unfold.html#mkCoreUnfolding"><span class="hs-identifier hs-var">mkCoreUnfolding</span></a></span><span> </span><span class="annot"><span class="annottext">UnfoldingSource
</span><a href="GHC.Core.html#InlineStable"><span class="hs-identifier hs-var">InlineStable</span></a></span><span>
</span><span id="line-158"></span><span>                    </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">True</span></span><span>         </span><span class="hs-comment">-- Note [Top-level flag on inline rules]</span><span>
</span><span id="line-159"></span><span>                    </span><span class="annot"><span class="annottext">CoreArg
</span><a href="#local-6989586621680863930"><span class="hs-identifier hs-var">expr'</span></a></span><span> </span><span class="annot"><span class="annottext">UnfoldingGuidance
</span><a href="#local-6989586621680863929"><span class="hs-identifier hs-var">guide</span></a></span><span>
</span><span id="line-160"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-161"></span><span>    </span><span id="local-6989586621680863930"><span class="annot"><span class="annottext">expr' :: CoreArg
</span><a href="#local-6989586621680863930"><span class="hs-identifier hs-var hs-var">expr'</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">HasDebugCallStack =&gt; DynFlags -&gt; CoreArg -&gt; CoreArg
DynFlags -&gt; CoreArg -&gt; CoreArg
</span><a href="GHC.Core.SimpleOpt.html#simpleOptExpr"><span class="hs-identifier hs-var">simpleOptExpr</span></a></span><span> </span><span class="annot"><span class="annottext">DynFlags
</span><a href="GHC.Driver.Session.html#unsafeGlobalDynFlags"><span class="hs-identifier hs-var">unsafeGlobalDynFlags</span></a></span><span> </span><span class="annot"><span class="annottext">CoreArg
</span><a href="#local-6989586621680863931"><span class="hs-identifier hs-var">expr</span></a></span><span>
</span><span id="line-162"></span><span>    </span><span id="local-6989586621680863929"><span class="annot"><span class="annottext">guide :: UnfoldingGuidance
</span><a href="#local-6989586621680863929"><span class="hs-identifier hs-var hs-var">guide</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">UnfWhen :: Int -&gt; Bool -&gt; Bool -&gt; UnfoldingGuidance
</span><a href="GHC.Core.html#UnfWhen"><span class="hs-identifier hs-type">UnfWhen</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">ug_arity :: Int
</span><a href="GHC.Core.html#ug_arity"><span class="hs-identifier hs-var">ug_arity</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863932"><span class="hs-identifier hs-var">arity</span></a></span><span>
</span><span id="line-163"></span><span>                    </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">ug_unsat_ok :: Bool
</span><a href="GHC.Core.html#ug_unsat_ok"><span class="hs-identifier hs-var">ug_unsat_ok</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="GHC.Core.html#needSaturated"><span class="hs-identifier hs-var">needSaturated</span></a></span><span>
</span><span id="line-164"></span><span>                    </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">ug_boring_ok :: Bool
</span><a href="GHC.Core.html#ug_boring_ok"><span class="hs-identifier hs-var">ug_boring_ok</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621680863926"><span class="hs-identifier hs-var">boring_ok</span></a></span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-165"></span><span>    </span><span class="hs-comment">-- See Note [INLINE pragmas and boring contexts] as to why we need to look</span><span>
</span><span id="line-166"></span><span>    </span><span class="hs-comment">-- at the arity here.</span><span>
</span><span id="line-167"></span><span>    </span><span id="local-6989586621680863926"><span class="annot"><span class="annottext">boring_ok :: Bool
</span><a href="#local-6989586621680863926"><span class="hs-identifier hs-var hs-var">boring_ok</span></a></span></span><span> </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863932"><span class="hs-identifier hs-var">arity</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Bool
forall a. Eq a =&gt; a -&gt; a -&gt; Bool
</span><span class="hs-operator hs-var">==</span></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">0</span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">True</span></span><span>
</span><span id="line-168"></span><span>              </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">CoreArg -&gt; Bool
</span><a href="GHC.Core.Unfold.html#inlineBoringOk"><span class="hs-identifier hs-var">inlineBoringOk</span></a></span><span> </span><span class="annot"><span class="annottext">CoreArg
</span><a href="#local-6989586621680863930"><span class="hs-identifier hs-var">expr'</span></a></span><span>
</span><span id="line-169"></span><span>
</span><span id="line-170"></span><span class="annot"><a href="GHC.Core.Unfold.html#mkInlinableUnfolding"><span class="hs-identifier hs-type">mkInlinableUnfolding</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Driver.Session.html#DynFlags"><span class="hs-identifier hs-type">DynFlags</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.html#CoreExpr"><span class="hs-identifier hs-type">CoreExpr</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.html#Unfolding"><span class="hs-identifier hs-type">Unfolding</span></a></span><span>
</span><span id="line-171"></span><span id="mkInlinableUnfolding"><span class="annot"><span class="annottext">mkInlinableUnfolding :: DynFlags -&gt; CoreArg -&gt; Unfolding
</span><a href="GHC.Core.Unfold.html#mkInlinableUnfolding"><span class="hs-identifier hs-var hs-var">mkInlinableUnfolding</span></a></span></span><span> </span><span id="local-6989586621680863923"><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680863923"><span class="hs-identifier hs-var">dflags</span></a></span></span><span> </span><span id="local-6989586621680863922"><span class="annot"><span class="annottext">CoreArg
</span><a href="#local-6989586621680863922"><span class="hs-identifier hs-var">expr</span></a></span></span><span>
</span><span id="line-172"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">DynFlags -&gt; UnfoldingSource -&gt; Bool -&gt; Bool -&gt; CoreArg -&gt; Unfolding
</span><a href="GHC.Core.Unfold.html#mkUnfolding"><span class="hs-identifier hs-var">mkUnfolding</span></a></span><span> </span><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680863923"><span class="hs-identifier hs-var">dflags</span></a></span><span> </span><span class="annot"><span class="annottext">UnfoldingSource
</span><a href="GHC.Core.html#InlineStable"><span class="hs-identifier hs-var">InlineStable</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">False</span></span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">False</span></span><span> </span><span class="annot"><span class="annottext">CoreArg
</span><a href="#local-6989586621680863921"><span class="hs-identifier hs-var">expr'</span></a></span><span>
</span><span id="line-173"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-174"></span><span>    </span><span id="local-6989586621680863921"><span class="annot"><span class="annottext">expr' :: CoreArg
</span><a href="#local-6989586621680863921"><span class="hs-identifier hs-var hs-var">expr'</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">HasDebugCallStack =&gt; DynFlags -&gt; CoreArg -&gt; CoreArg
DynFlags -&gt; CoreArg -&gt; CoreArg
</span><a href="GHC.Core.SimpleOpt.html#simpleOptExpr"><span class="hs-identifier hs-var">simpleOptExpr</span></a></span><span> </span><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680863923"><span class="hs-identifier hs-var">dflags</span></a></span><span> </span><span class="annot"><span class="annottext">CoreArg
</span><a href="#local-6989586621680863922"><span class="hs-identifier hs-var">expr</span></a></span><span>
</span><span id="line-175"></span><span>
</span><span id="line-176"></span><span class="annot"><a href="GHC.Core.Unfold.html#specUnfolding"><span class="hs-identifier hs-type">specUnfolding</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Driver.Session.html#DynFlags"><span class="hs-identifier hs-type">DynFlags</span></a></span><span>
</span><span id="line-177"></span><span>              </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Types.Var.html#Var"><span class="hs-identifier hs-type">Var</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#CoreExpr"><span class="hs-identifier hs-type">CoreExpr</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.html#CoreExpr"><span class="hs-identifier hs-type">CoreExpr</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-178"></span><span>              </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.html#CoreArg"><span class="hs-identifier hs-type">CoreArg</span></a></span><span class="hs-special">]</span><span>   </span><span class="hs-comment">-- LHS arguments in the RULE</span><span>
</span><span id="line-179"></span><span>              </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.html#Unfolding"><span class="hs-identifier hs-type">Unfolding</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.html#Unfolding"><span class="hs-identifier hs-type">Unfolding</span></a></span><span>
</span><span id="line-180"></span><span class="hs-comment">-- See Note [Specialising unfoldings]</span><span>
</span><span id="line-181"></span><span class="hs-comment">-- specUnfolding spec_bndrs spec_args unf</span><span>
</span><span id="line-182"></span><span class="hs-comment">--   = \spec_bndrs. unf spec_args</span><span>
</span><span id="line-183"></span><span class="hs-comment">--</span><span>
</span><span id="line-184"></span><span id="specUnfolding"><span class="annot"><span class="annottext">specUnfolding :: DynFlags
-&gt; [Id]
-&gt; (CoreArg -&gt; CoreArg)
-&gt; [CoreArg]
-&gt; Unfolding
-&gt; Unfolding
</span><a href="GHC.Core.Unfold.html#specUnfolding"><span class="hs-identifier hs-var hs-var">specUnfolding</span></a></span></span><span> </span><span id="local-6989586621680863919"><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680863919"><span class="hs-identifier hs-var">dflags</span></a></span></span><span> </span><span id="local-6989586621680863918"><span class="annot"><span class="annottext">[Id]
</span><a href="#local-6989586621680863918"><span class="hs-identifier hs-var">spec_bndrs</span></a></span></span><span> </span><span id="local-6989586621680863917"><span class="annot"><span class="annottext">CoreArg -&gt; CoreArg
</span><a href="#local-6989586621680863917"><span class="hs-identifier hs-var">spec_app</span></a></span></span><span> </span><span id="local-6989586621680863916"><span class="annot"><span class="annottext">[CoreArg]
</span><a href="#local-6989586621680863916"><span class="hs-identifier hs-var">rule_lhs_args</span></a></span></span><span>
</span><span id="line-185"></span><span>              </span><span id="local-6989586621680863915"><span class="annot"><span class="annottext">df :: Unfolding
</span><a href="#local-6989586621680863915"><span class="hs-identifier hs-var">df</span></a></span></span><span class="hs-glyph">@</span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#DFunUnfolding"><span class="hs-identifier hs-type">DFunUnfolding</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">df_bndrs :: Unfolding -&gt; [Id]
</span><a href="GHC.Core.html#df_bndrs"><span class="hs-identifier hs-var">df_bndrs</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680863914"><span class="annot"><span class="annottext">[Id]
</span><a href="#local-6989586621680863914"><span class="hs-identifier hs-var">old_bndrs</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">df_con :: Unfolding -&gt; DataCon
</span><a href="GHC.Core.html#df_con"><span class="hs-identifier hs-var">df_con</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680863913"><span class="annot"><span class="annottext">DataCon
</span><a href="#local-6989586621680863913"><span class="hs-identifier hs-var">con</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">df_args :: Unfolding -&gt; [CoreArg]
</span><a href="GHC.Core.html#df_args"><span class="hs-identifier hs-var">df_args</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680863912"><span class="annot"><span class="annottext">[CoreArg]
</span><a href="#local-6989586621680863912"><span class="hs-identifier hs-var">args</span></a></span></span><span> </span><span class="hs-special">}</span><span class="hs-special">)</span><span>
</span><span id="line-186"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">ASSERT2</span><span class="hs-special">(</span><span> </span><span class="hs-identifier">rule_lhs_args</span><span> </span><span class="hs-special">`</span><span class="hs-identifier">equalLength</span><span class="hs-special">`</span><span> </span><span class="hs-identifier">old_bndrs</span><span>
</span><span id="line-187"></span><span>           </span><span class="hs-special">,</span><span> </span><span class="hs-identifier">ppr</span><span> </span><span class="hs-identifier">df</span><span> </span><span class="hs-operator">$$</span><span> </span><span class="hs-identifier">ppr</span><span> </span><span class="hs-identifier">rule_lhs_args</span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-188"></span><span>           </span><span class="hs-comment">-- For this ASSERT see Note [DFunUnfoldings] in GHC.Core.Opt.Specialise</span><span>
</span><span id="line-189"></span><span>    </span><span class="annot"><span class="annottext">[Id] -&gt; DataCon -&gt; [CoreArg] -&gt; Unfolding
</span><a href="GHC.Core.Unfold.html#mkDFunUnfolding"><span class="hs-identifier hs-var">mkDFunUnfolding</span></a></span><span> </span><span class="annot"><span class="annottext">[Id]
</span><a href="#local-6989586621680863918"><span class="hs-identifier hs-var">spec_bndrs</span></a></span><span> </span><span class="annot"><span class="annottext">DataCon
</span><a href="#local-6989586621680863913"><span class="hs-identifier hs-var">con</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">(CoreArg -&gt; CoreArg) -&gt; [CoreArg] -&gt; [CoreArg]
forall a b. (a -&gt; b) -&gt; [a] -&gt; [b]
</span><a href="../../base/src/GHC.Base.html#map"><span class="hs-identifier hs-var">map</span></a></span><span> </span><span class="annot"><span class="annottext">CoreArg -&gt; CoreArg
</span><a href="#local-6989586621680863904"><span class="hs-identifier hs-var">spec_arg</span></a></span><span> </span><span class="annot"><span class="annottext">[CoreArg]
</span><a href="#local-6989586621680863912"><span class="hs-identifier hs-var">args</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-190"></span><span>      </span><span class="hs-comment">-- For DFunUnfoldings we transform</span><span>
</span><span id="line-191"></span><span>      </span><span class="hs-comment">--       \obs. MkD &lt;op1&gt; ... &lt;opn&gt;</span><span>
</span><span id="line-192"></span><span>      </span><span class="hs-comment">-- to</span><span>
</span><span id="line-193"></span><span>      </span><span class="hs-comment">--       \sbs. MkD ((\obs. &lt;op1&gt;) spec_args) ... ditto &lt;opn&gt;</span><span>
</span><span id="line-194"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-195"></span><span>    </span><span id="local-6989586621680863904"><span class="annot"><span class="annottext">spec_arg :: CoreArg -&gt; CoreArg
</span><a href="#local-6989586621680863904"><span class="hs-identifier hs-var hs-var">spec_arg</span></a></span></span><span> </span><span id="local-6989586621680863902"><span class="annot"><span class="annottext">CoreArg
</span><a href="#local-6989586621680863902"><span class="hs-identifier hs-var">arg</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">HasDebugCallStack =&gt; DynFlags -&gt; CoreArg -&gt; CoreArg
DynFlags -&gt; CoreArg -&gt; CoreArg
</span><a href="GHC.Core.SimpleOpt.html#simpleOptExpr"><span class="hs-identifier hs-var">simpleOptExpr</span></a></span><span> </span><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680863919"><span class="hs-identifier hs-var">dflags</span></a></span><span> </span><span class="annot"><span class="annottext">(CoreArg -&gt; CoreArg) -&gt; CoreArg -&gt; CoreArg
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span>
</span><span id="line-196"></span><span>                   </span><span class="annot"><span class="annottext">CoreArg -&gt; CoreArg
</span><a href="#local-6989586621680863917"><span class="hs-identifier hs-var">spec_app</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">[Id] -&gt; CoreArg -&gt; CoreArg
forall b. [b] -&gt; Expr b -&gt; Expr b
</span><a href="GHC.Core.html#mkLams"><span class="hs-identifier hs-var">mkLams</span></a></span><span> </span><span class="annot"><span class="annottext">[Id]
</span><a href="#local-6989586621680863914"><span class="hs-identifier hs-var">old_bndrs</span></a></span><span> </span><span class="annot"><span class="annottext">CoreArg
</span><a href="#local-6989586621680863902"><span class="hs-identifier hs-var">arg</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-197"></span><span>                   </span><span class="hs-comment">-- The beta-redexes created by spec_app will be</span><span>
</span><span id="line-198"></span><span>                   </span><span class="hs-comment">-- simplified away by simplOptExpr</span><span>
</span><span id="line-199"></span><span>
</span><span id="line-200"></span><span class="annot"><a href="GHC.Core.Unfold.html#specUnfolding"><span class="hs-identifier hs-var">specUnfolding</span></a></span><span> </span><span id="local-6989586621680863900"><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680863900"><span class="hs-identifier hs-var">dflags</span></a></span></span><span> </span><span id="local-6989586621680863899"><span class="annot"><span class="annottext">[Id]
</span><a href="#local-6989586621680863899"><span class="hs-identifier hs-var">spec_bndrs</span></a></span></span><span> </span><span id="local-6989586621680863898"><span class="annot"><span class="annottext">CoreArg -&gt; CoreArg
</span><a href="#local-6989586621680863898"><span class="hs-identifier hs-var">spec_app</span></a></span></span><span> </span><span id="local-6989586621680863897"><span class="annot"><span class="annottext">[CoreArg]
</span><a href="#local-6989586621680863897"><span class="hs-identifier hs-var">rule_lhs_args</span></a></span></span><span>
</span><span id="line-201"></span><span>              </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#CoreUnfolding"><span class="hs-identifier hs-type">CoreUnfolding</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">uf_src :: Unfolding -&gt; UnfoldingSource
</span><a href="GHC.Core.html#uf_src"><span class="hs-identifier hs-var">uf_src</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680863896"><span class="annot"><span class="annottext">UnfoldingSource
</span><a href="#local-6989586621680863896"><span class="hs-identifier hs-var">src</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">uf_tmpl :: Unfolding -&gt; CoreArg
</span><a href="GHC.Core.html#uf_tmpl"><span class="hs-identifier hs-var">uf_tmpl</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680863895"><span class="annot"><span class="annottext">CoreArg
</span><a href="#local-6989586621680863895"><span class="hs-identifier hs-var">tmpl</span></a></span></span><span>
</span><span id="line-202"></span><span>                             </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">uf_is_top :: Unfolding -&gt; Bool
</span><a href="GHC.Core.html#uf_is_top"><span class="hs-identifier hs-var">uf_is_top</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680863894"><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621680863894"><span class="hs-identifier hs-var">top_lvl</span></a></span></span><span>
</span><span id="line-203"></span><span>                             </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">uf_guidance :: Unfolding -&gt; UnfoldingGuidance
</span><a href="GHC.Core.html#uf_guidance"><span class="hs-identifier hs-var">uf_guidance</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680863892"><span class="annot"><span class="annottext">UnfoldingGuidance
</span><a href="#local-6989586621680863892"><span class="hs-identifier hs-var">old_guidance</span></a></span></span><span> </span><span class="hs-special">}</span><span class="hs-special">)</span><span>
</span><span id="line-204"></span><span> </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">UnfoldingSource -&gt; Bool
</span><a href="GHC.Core.html#isStableSource"><span class="hs-identifier hs-var">isStableSource</span></a></span><span> </span><span class="annot"><span class="annottext">UnfoldingSource
</span><a href="#local-6989586621680863896"><span class="hs-identifier hs-var">src</span></a></span><span>  </span><span class="hs-comment">-- See Note [Specialising unfoldings]</span><span>
</span><span id="line-205"></span><span> </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Core.html#UnfWhen"><span class="hs-identifier hs-type">UnfWhen</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">ug_arity :: UnfoldingGuidance -&gt; Int
</span><a href="GHC.Core.html#ug_arity"><span class="hs-identifier hs-var">ug_arity</span></a></span><span>     </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680863891"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863891"><span class="hs-identifier hs-var">old_arity</span></a></span></span><span> </span><span class="hs-special">}</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">UnfoldingGuidance
</span><a href="#local-6989586621680863892"><span class="hs-identifier hs-var">old_guidance</span></a></span><span>
</span><span id="line-206"></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">UnfoldingSource
-&gt; Bool -&gt; CoreArg -&gt; UnfoldingGuidance -&gt; Unfolding
</span><a href="GHC.Core.Unfold.html#mkCoreUnfolding"><span class="hs-identifier hs-var">mkCoreUnfolding</span></a></span><span> </span><span class="annot"><span class="annottext">UnfoldingSource
</span><a href="#local-6989586621680863896"><span class="hs-identifier hs-var">src</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621680863894"><span class="hs-identifier hs-var">top_lvl</span></a></span><span> </span><span class="annot"><span class="annottext">CoreArg
</span><a href="#local-6989586621680863890"><span class="hs-identifier hs-var">new_tmpl</span></a></span><span>
</span><span id="line-207"></span><span>                   </span><span class="hs-special">(</span><span class="annot"><span class="annottext">UnfoldingGuidance
</span><a href="#local-6989586621680863892"><span class="hs-identifier hs-var">old_guidance</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">ug_arity :: Int
</span><a href="GHC.Core.html#ug_arity"><span class="hs-identifier hs-var">ug_arity</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863891"><span class="hs-identifier hs-var">old_arity</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="../../base/src/GHC.Num.html#-"><span class="hs-glyph hs-var">-</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863889"><span class="hs-identifier hs-var">arity_decrease</span></a></span><span> </span><span class="hs-special">}</span><span class="hs-special">)</span><span>
</span><span id="line-208"></span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-209"></span><span>   </span><span id="local-6989586621680863890"><span class="annot"><span class="annottext">new_tmpl :: CoreArg
</span><a href="#local-6989586621680863890"><span class="hs-identifier hs-var hs-var">new_tmpl</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">HasDebugCallStack =&gt; DynFlags -&gt; CoreArg -&gt; CoreArg
DynFlags -&gt; CoreArg -&gt; CoreArg
</span><a href="GHC.Core.SimpleOpt.html#simpleOptExpr"><span class="hs-identifier hs-var">simpleOptExpr</span></a></span><span> </span><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680863900"><span class="hs-identifier hs-var">dflags</span></a></span><span> </span><span class="annot"><span class="annottext">(CoreArg -&gt; CoreArg) -&gt; CoreArg -&gt; CoreArg
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span>
</span><span id="line-210"></span><span>              </span><span class="annot"><span class="annottext">[Id] -&gt; CoreArg -&gt; CoreArg
forall b. [b] -&gt; Expr b -&gt; Expr b
</span><a href="GHC.Core.html#mkLams"><span class="hs-identifier hs-var">mkLams</span></a></span><span> </span><span class="annot"><span class="annottext">[Id]
</span><a href="#local-6989586621680863899"><span class="hs-identifier hs-var">spec_bndrs</span></a></span><span>    </span><span class="annot"><span class="annottext">(CoreArg -&gt; CoreArg) -&gt; CoreArg -&gt; CoreArg
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span>
</span><span id="line-211"></span><span>              </span><span class="annot"><span class="annottext">CoreArg -&gt; CoreArg
</span><a href="#local-6989586621680863898"><span class="hs-identifier hs-var">spec_app</span></a></span><span> </span><span class="annot"><span class="annottext">CoreArg
</span><a href="#local-6989586621680863895"><span class="hs-identifier hs-var">tmpl</span></a></span><span>  </span><span class="hs-comment">-- The beta-redexes created by spec_app</span><span>
</span><span id="line-212"></span><span>                             </span><span class="hs-comment">-- will besimplified away by simplOptExpr</span><span>
</span><span id="line-213"></span><span>   </span><span id="local-6989586621680863889"><span class="annot"><span class="annottext">arity_decrease :: Int
</span><a href="#local-6989586621680863889"><span class="hs-identifier hs-var hs-var">arity_decrease</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(CoreArg -&gt; Bool) -&gt; [CoreArg] -&gt; Int
forall a. (a -&gt; Bool) -&gt; [a] -&gt; Int
</span><a href="GHC.Utils.Misc.html#count"><span class="hs-identifier hs-var">count</span></a></span><span> </span><span class="annot"><span class="annottext">CoreArg -&gt; Bool
forall b. Expr b -&gt; Bool
</span><a href="GHC.Core.html#isValArg"><span class="hs-identifier hs-var">isValArg</span></a></span><span> </span><span class="annot"><span class="annottext">[CoreArg]
</span><a href="#local-6989586621680863897"><span class="hs-identifier hs-var">rule_lhs_args</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="../../base/src/GHC.Num.html#-"><span class="hs-glyph hs-var">-</span></a></span><span> </span><span class="annot"><span class="annottext">(Id -&gt; Bool) -&gt; [Id] -&gt; Int
forall a. (a -&gt; Bool) -&gt; [a] -&gt; Int
</span><a href="GHC.Utils.Misc.html#count"><span class="hs-identifier hs-var">count</span></a></span><span> </span><span class="annot"><span class="annottext">Id -&gt; Bool
</span><a href="GHC.Types.Var.html#isId"><span class="hs-identifier hs-var">isId</span></a></span><span> </span><span class="annot"><span class="annottext">[Id]
</span><a href="#local-6989586621680863899"><span class="hs-identifier hs-var">spec_bndrs</span></a></span><span>
</span><span id="line-214"></span><span>
</span><span id="line-215"></span><span>
</span><span id="line-216"></span><span class="annot"><a href="GHC.Core.Unfold.html#specUnfolding"><span class="hs-identifier hs-var">specUnfolding</span></a></span><span> </span><span class="annot"><span class="annottext">DynFlags
</span><span class="hs-identifier">_</span></span><span> </span><span class="annot"><span class="annottext">[Id]
</span><span class="hs-identifier">_</span></span><span> </span><span class="annot"><span class="annottext">CoreArg -&gt; CoreArg
</span><span class="hs-identifier">_</span></span><span> </span><span class="annot"><span class="annottext">[CoreArg]
</span><span class="hs-identifier">_</span></span><span> </span><span class="annot"><span class="annottext">Unfolding
</span><span class="hs-identifier">_</span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Unfolding
</span><a href="GHC.Core.html#noUnfolding"><span class="hs-identifier hs-var">noUnfolding</span></a></span><span>
</span><span id="line-217"></span><span>
</span><span id="line-218"></span><span class="hs-comment">{- Note [Specialising unfoldings]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
When we specialise a function for some given type-class arguments, we use
specUnfolding to specialise its unfolding.  Some important points:

* If the original function has a DFunUnfolding, the specialised one
  must do so too!  Otherwise we lose the magic rules that make it
  interact with ClassOps

* There is a bit of hack for INLINABLE functions:
     f :: Ord a =&gt; ....
     f = &lt;big-rhs&gt;
     {- INLINABLE f #-}
  Now if we specialise f, should the specialised version still have
  an INLINABLE pragma?  If it does, we'll capture a specialised copy
  of &lt;big-rhs&gt; as its unfolding, and that probably won't inline.  But
  if we don't, the specialised version of &lt;big-rhs&gt; might be small
  enough to inline at a call site. This happens with Control.Monad.liftM3,
  and can cause a lot more allocation as a result (nofib n-body shows this).

  Moreover, keeping the INLINABLE thing isn't much help, because
  the specialised function (probably) isn't overloaded any more.

  Conclusion: drop the INLINEALE pragma.  In practice what this means is:
     if a stable unfolding has UnfoldingGuidance of UnfWhen,
        we keep it (so the specialised thing too will always inline)
     if a stable unfolding has UnfoldingGuidance of UnfIfGoodArgs
        (which arises from INLINABLE), we discard it

Note [Honour INLINE on 0-ary bindings]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Consider

   x = &lt;expensive&gt;
   {-# INLINE x #-}

   f y = ...x...

The semantics of an INLINE pragma is

  inline x at every call site, provided it is saturated;
  that is, applied to at least as many arguments as appear
  on the LHS of the Haskell source definition.

(This source-code-derived arity is stored in the `ug_arity` field of
the `UnfoldingGuidance`.)

In the example, x's ug_arity is 0, so we should inline it at every use
site.  It's rare to have such an INLINE pragma (usually INLINE Is on
functions), but it's occasionally very important (#15578, #15519).
In #15519 we had something like
   x = case (g a b) of I# r -&gt; T r
   {-# INLINE x #-}
   f y = ...(h x)....

where h is strict.  So we got
   f y = ...(case g a b of I# r -&gt; h (T r))...

and that in turn allowed SpecConstr to ramp up performance.

How do we deliver on this?  By adjusting the ug_boring_ok
flag in mkInlineUnfoldingWithArity; see
Note [INLINE pragmas and boring contexts]

NB: there is a real risk that full laziness will float it right back
out again. Consider again
  x = factorial 200
  {-# INLINE x #-}
  f y = ...x...

After inlining we get
  f y = ...(factorial 200)...

but it's entirely possible that full laziness will do
  lvl23 = factorial 200
  f y = ...lvl23...

That's a problem for another day.

Note [INLINE pragmas and boring contexts]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
An INLINE pragma uses mkInlineUnfoldingWithArity to build the
unfolding.  That sets the ug_boring_ok flag to False if the function
is not tiny (inlineBoringOK), so that even INLINE functions are not
inlined in an utterly boring context.  E.g.
     \x y. Just (f y x)
Nothing is gained by inlining f here, even if it has an INLINE
pragma.

But for 0-ary bindings, we want to inline regardless; see
Note [Honour INLINE on 0-ary bindings].

I'm a bit worried that it's possible for the same kind of problem
to arise for non-0-ary functions too, but let's wait and see.
-}</span><span>
</span><span id="line-313"></span><span>
</span><span id="line-314"></span><span class="annot"><a href="GHC.Core.Unfold.html#mkUnfolding"><span class="hs-identifier hs-type">mkUnfolding</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Driver.Session.html#DynFlags"><span class="hs-identifier hs-type">DynFlags</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.html#UnfoldingSource"><span class="hs-identifier hs-type">UnfoldingSource</span></a></span><span>
</span><span id="line-315"></span><span>            </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Bool</span></span><span>       </span><span class="hs-comment">-- Is top-level</span><span>
</span><span id="line-316"></span><span>            </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Bool</span></span><span>       </span><span class="hs-comment">-- Definitely a bottoming binding</span><span>
</span><span id="line-317"></span><span>                          </span><span class="hs-comment">-- (only relevant for top-level bindings)</span><span>
</span><span id="line-318"></span><span>            </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.html#CoreExpr"><span class="hs-identifier hs-type">CoreExpr</span></a></span><span>
</span><span id="line-319"></span><span>            </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.html#Unfolding"><span class="hs-identifier hs-type">Unfolding</span></a></span><span>
</span><span id="line-320"></span><span class="hs-comment">-- Calculates unfolding guidance</span><span>
</span><span id="line-321"></span><span class="hs-comment">-- Occurrence-analyses the expression before capturing it</span><span>
</span><span id="line-322"></span><span id="mkUnfolding"><span class="annot"><span class="annottext">mkUnfolding :: DynFlags -&gt; UnfoldingSource -&gt; Bool -&gt; Bool -&gt; CoreArg -&gt; Unfolding
</span><a href="GHC.Core.Unfold.html#mkUnfolding"><span class="hs-identifier hs-var hs-var">mkUnfolding</span></a></span></span><span> </span><span id="local-6989586621680863883"><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680863883"><span class="hs-identifier hs-var">dflags</span></a></span></span><span> </span><span id="local-6989586621680863882"><span class="annot"><span class="annottext">UnfoldingSource
</span><a href="#local-6989586621680863882"><span class="hs-identifier hs-var">src</span></a></span></span><span> </span><span id="local-6989586621680863881"><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621680863881"><span class="hs-identifier hs-var">top_lvl</span></a></span></span><span> </span><span id="local-6989586621680863880"><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621680863880"><span class="hs-identifier hs-var">is_bottoming</span></a></span></span><span> </span><span id="local-6989586621680863879"><span class="annot"><span class="annottext">CoreArg
</span><a href="#local-6989586621680863879"><span class="hs-identifier hs-var">expr</span></a></span></span><span>
</span><span id="line-323"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">UnfoldingSource
-&gt; Bool -&gt; CoreArg -&gt; UnfoldingGuidance -&gt; Unfolding
</span><a href="GHC.Core.Unfold.html#mkCoreUnfolding"><span class="hs-identifier hs-var">mkCoreUnfolding</span></a></span><span> </span><span class="annot"><span class="annottext">UnfoldingSource
</span><a href="#local-6989586621680863882"><span class="hs-identifier hs-var">src</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621680863881"><span class="hs-identifier hs-var">top_lvl</span></a></span><span> </span><span class="annot"><span class="annottext">CoreArg
</span><a href="#local-6989586621680863879"><span class="hs-identifier hs-var">expr</span></a></span><span> </span><span class="annot"><span class="annottext">UnfoldingGuidance
</span><a href="#local-6989586621680863878"><span class="hs-identifier hs-var">guidance</span></a></span><span>
</span><span id="line-324"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-325"></span><span>    </span><span id="local-6989586621680863877"><span class="annot"><span class="annottext">is_top_bottoming :: Bool
</span><a href="#local-6989586621680863877"><span class="hs-identifier hs-var hs-var">is_top_bottoming</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621680863881"><span class="hs-identifier hs-var">top_lvl</span></a></span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Bool -&gt; Bool
</span><span class="hs-operator hs-var">&amp;&amp;</span></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621680863880"><span class="hs-identifier hs-var">is_bottoming</span></a></span><span>
</span><span id="line-326"></span><span>    </span><span id="local-6989586621680863878"><span class="annot"><span class="annottext">guidance :: UnfoldingGuidance
</span><a href="#local-6989586621680863878"><span class="hs-identifier hs-var hs-var">guidance</span></a></span></span><span>         </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">DynFlags -&gt; Bool -&gt; CoreArg -&gt; UnfoldingGuidance
</span><a href="GHC.Core.Unfold.html#calcUnfoldingGuidance"><span class="hs-identifier hs-var">calcUnfoldingGuidance</span></a></span><span> </span><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680863883"><span class="hs-identifier hs-var">dflags</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621680863877"><span class="hs-identifier hs-var">is_top_bottoming</span></a></span><span> </span><span class="annot"><span class="annottext">CoreArg
</span><a href="#local-6989586621680863879"><span class="hs-identifier hs-var">expr</span></a></span><span>
</span><span id="line-327"></span><span>        </span><span class="hs-comment">-- NB: *not* (calcUnfoldingGuidance (occurAnalyseExpr expr))!</span><span>
</span><span id="line-328"></span><span>        </span><span class="hs-comment">-- See Note [Calculate unfolding guidance on the non-occ-anal'd expression]</span><span>
</span><span id="line-329"></span><span>
</span><span id="line-330"></span><span class="annot"><a href="GHC.Core.Unfold.html#mkCoreUnfolding"><span class="hs-identifier hs-type">mkCoreUnfolding</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.html#UnfoldingSource"><span class="hs-identifier hs-type">UnfoldingSource</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Bool</span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.html#CoreExpr"><span class="hs-identifier hs-type">CoreExpr</span></a></span><span>
</span><span id="line-331"></span><span>                </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.html#UnfoldingGuidance"><span class="hs-identifier hs-type">UnfoldingGuidance</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.html#Unfolding"><span class="hs-identifier hs-type">Unfolding</span></a></span><span>
</span><span id="line-332"></span><span class="hs-comment">-- Occurrence-analyses the expression before capturing it</span><span>
</span><span id="line-333"></span><span id="mkCoreUnfolding"><span class="annot"><span class="annottext">mkCoreUnfolding :: UnfoldingSource
-&gt; Bool -&gt; CoreArg -&gt; UnfoldingGuidance -&gt; Unfolding
</span><a href="GHC.Core.Unfold.html#mkCoreUnfolding"><span class="hs-identifier hs-var hs-var">mkCoreUnfolding</span></a></span></span><span> </span><span id="local-6989586621680863876"><span class="annot"><span class="annottext">UnfoldingSource
</span><a href="#local-6989586621680863876"><span class="hs-identifier hs-var">src</span></a></span></span><span> </span><span id="local-6989586621680863875"><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621680863875"><span class="hs-identifier hs-var">top_lvl</span></a></span></span><span> </span><span id="local-6989586621680863874"><span class="annot"><span class="annottext">CoreArg
</span><a href="#local-6989586621680863874"><span class="hs-identifier hs-var">expr</span></a></span></span><span> </span><span id="local-6989586621680863873"><span class="annot"><span class="annottext">UnfoldingGuidance
</span><a href="#local-6989586621680863873"><span class="hs-identifier hs-var">guidance</span></a></span></span><span>
</span><span id="line-334"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">CoreUnfolding :: CoreArg
-&gt; UnfoldingSource
-&gt; Bool
-&gt; Bool
-&gt; Bool
-&gt; Bool
-&gt; Bool
-&gt; UnfoldingGuidance
-&gt; Unfolding
</span><a href="GHC.Core.html#CoreUnfolding"><span class="hs-identifier hs-type">CoreUnfolding</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">uf_tmpl :: CoreArg
</span><a href="GHC.Core.html#uf_tmpl"><span class="hs-identifier hs-var">uf_tmpl</span></a></span><span>         </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">CoreArg -&gt; CoreArg
</span><a href="GHC.Core.Opt.OccurAnal.html#occurAnalyseExpr"><span class="hs-identifier hs-var">occurAnalyseExpr</span></a></span><span> </span><span class="annot"><span class="annottext">CoreArg
</span><a href="#local-6989586621680863874"><span class="hs-identifier hs-var">expr</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-335"></span><span>                      </span><span class="hs-comment">-- See Note [Occurrence analysis of unfoldings]</span><span>
</span><span id="line-336"></span><span>                    </span><span class="annot"><span class="annottext">uf_src :: UnfoldingSource
</span><a href="GHC.Core.html#uf_src"><span class="hs-identifier hs-var">uf_src</span></a></span><span>          </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">UnfoldingSource
</span><a href="#local-6989586621680863876"><span class="hs-identifier hs-var">src</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-337"></span><span>                    </span><span class="annot"><span class="annottext">uf_is_top :: Bool
</span><a href="GHC.Core.html#uf_is_top"><span class="hs-identifier hs-var">uf_is_top</span></a></span><span>       </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621680863875"><span class="hs-identifier hs-var">top_lvl</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-338"></span><span>                    </span><span class="annot"><span class="annottext">uf_is_value :: Bool
</span><a href="GHC.Core.html#uf_is_value"><span class="hs-identifier hs-var">uf_is_value</span></a></span><span>     </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">CoreArg -&gt; Bool
</span><a href="GHC.Core.Utils.html#exprIsHNF"><span class="hs-identifier hs-var">exprIsHNF</span></a></span><span>        </span><span class="annot"><span class="annottext">CoreArg
</span><a href="#local-6989586621680863874"><span class="hs-identifier hs-var">expr</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-339"></span><span>                    </span><span class="annot"><span class="annottext">uf_is_conlike :: Bool
</span><a href="GHC.Core.html#uf_is_conlike"><span class="hs-identifier hs-var">uf_is_conlike</span></a></span><span>   </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">CoreArg -&gt; Bool
</span><a href="GHC.Core.Utils.html#exprIsConLike"><span class="hs-identifier hs-var">exprIsConLike</span></a></span><span>    </span><span class="annot"><span class="annottext">CoreArg
</span><a href="#local-6989586621680863874"><span class="hs-identifier hs-var">expr</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-340"></span><span>                    </span><span class="annot"><span class="annottext">uf_is_work_free :: Bool
</span><a href="GHC.Core.html#uf_is_work_free"><span class="hs-identifier hs-var">uf_is_work_free</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">CoreArg -&gt; Bool
</span><a href="GHC.Core.Utils.html#exprIsWorkFree"><span class="hs-identifier hs-var">exprIsWorkFree</span></a></span><span>   </span><span class="annot"><span class="annottext">CoreArg
</span><a href="#local-6989586621680863874"><span class="hs-identifier hs-var">expr</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-341"></span><span>                    </span><span class="annot"><span class="annottext">uf_expandable :: Bool
</span><a href="GHC.Core.html#uf_expandable"><span class="hs-identifier hs-var">uf_expandable</span></a></span><span>   </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">CoreArg -&gt; Bool
</span><a href="GHC.Core.Utils.html#exprIsExpandable"><span class="hs-identifier hs-var">exprIsExpandable</span></a></span><span> </span><span class="annot"><span class="annottext">CoreArg
</span><a href="#local-6989586621680863874"><span class="hs-identifier hs-var">expr</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-342"></span><span>                    </span><span class="annot"><span class="annottext">uf_guidance :: UnfoldingGuidance
</span><a href="GHC.Core.html#uf_guidance"><span class="hs-identifier hs-var">uf_guidance</span></a></span><span>     </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">UnfoldingGuidance
</span><a href="#local-6989586621680863873"><span class="hs-identifier hs-var">guidance</span></a></span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-343"></span><span>
</span><span id="line-344"></span><span>
</span><span id="line-345"></span><span class="hs-comment">{-
Note [Occurrence analysis of unfoldings]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
We do occurrence-analysis of unfoldings once and for all, when the
unfolding is built, rather than each time we inline them.

But given this decision it's vital that we do
*always* do it.  Consider this unfolding
    \x -&gt; letrec { f = ...g...; g* = f } in body
where g* is (for some strange reason) the loop breaker.  If we don't
occ-anal it when reading it in, we won't mark g as a loop breaker, and
we may inline g entirely in body, dropping its binding, and leaving
the occurrence in f out of scope. This happened in #8892, where
the unfolding in question was a DFun unfolding.

But more generally, the simplifier is designed on the
basis that it is looking at occurrence-analysed expressions, so better
ensure that they actually are.

Note [Calculate unfolding guidance on the non-occ-anal'd expression]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Notice that we give the non-occur-analysed expression to
calcUnfoldingGuidance.  In some ways it'd be better to occur-analyse
first; for example, sometimes during simplification, there's a large
let-bound thing which has been substituted, and so is now dead; so
'expr' contains two copies of the thing while the occurrence-analysed
expression doesn't.

Nevertheless, we *don't* and *must not* occ-analyse before computing
the size because

a) The size computation bales out after a while, whereas occurrence
   analysis does not.

b) Residency increases sharply if you occ-anal first.  I'm not
   100% sure why, but it's a large effect.  Compiling Cabal went
   from residency of 534M to over 800M with this one change.

This can occasionally mean that the guidance is very pessimistic;
it gets fixed up next round.  And it should be rare, because large
let-bound things that are dead are usually caught by preInlineUnconditionally


************************************************************************
*                                                                      *
\subsection{The UnfoldingGuidance type}
*                                                                      *
************************************************************************
-}</span><span>
</span><span id="line-394"></span><span>
</span><span id="line-395"></span><span class="annot"><a href="GHC.Core.Unfold.html#inlineBoringOk"><span class="hs-identifier hs-type">inlineBoringOk</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.html#CoreExpr"><span class="hs-identifier hs-type">CoreExpr</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Bool</span></span><span>
</span><span id="line-396"></span><span class="hs-comment">-- See Note [INLINE for small functions]</span><span>
</span><span id="line-397"></span><span class="hs-comment">-- True =&gt; the result of inlining the expression is</span><span>
</span><span id="line-398"></span><span class="hs-comment">--         no bigger than the expression itself</span><span>
</span><span id="line-399"></span><span class="hs-comment">--     eg      (\x y -&gt; f y x)</span><span>
</span><span id="line-400"></span><span class="hs-comment">-- This is a quick and dirty version. It doesn't attempt</span><span>
</span><span id="line-401"></span><span class="hs-comment">-- to deal with  (\x y z -&gt; x (y z))</span><span>
</span><span id="line-402"></span><span class="hs-comment">-- The really important one is (x `cast` c)</span><span>
</span><span id="line-403"></span><span id="inlineBoringOk"><span class="annot"><span class="annottext">inlineBoringOk :: CoreArg -&gt; Bool
</span><a href="GHC.Core.Unfold.html#inlineBoringOk"><span class="hs-identifier hs-var hs-var">inlineBoringOk</span></a></span></span><span> </span><span id="local-6989586621680863864"><span class="annot"><span class="annottext">CoreArg
</span><a href="#local-6989586621680863864"><span class="hs-identifier hs-var">e</span></a></span></span><span>
</span><span id="line-404"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int -&gt; CoreArg -&gt; Bool
</span><a href="#local-6989586621680863863"><span class="hs-identifier hs-var">go</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">0</span></span><span> </span><span class="annot"><span class="annottext">CoreArg
</span><a href="#local-6989586621680863864"><span class="hs-identifier hs-var">e</span></a></span><span>
</span><span id="line-405"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-406"></span><span>    </span><span class="annot"><a href="#local-6989586621680863863"><span class="hs-identifier hs-type">go</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Int</span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.html#CoreExpr"><span class="hs-identifier hs-type">CoreExpr</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Bool</span></span><span>
</span><span id="line-407"></span><span>    </span><span id="local-6989586621680863863"><span class="annot"><span class="annottext">go :: Int -&gt; CoreArg -&gt; Bool
</span><a href="#local-6989586621680863863"><span class="hs-identifier hs-var hs-var">go</span></a></span></span><span> </span><span id="local-6989586621680863862"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863862"><span class="hs-identifier hs-var">credit</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#Lam"><span class="hs-identifier hs-type">Lam</span></a></span><span> </span><span id="local-6989586621680863860"><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680863860"><span class="hs-identifier hs-var">x</span></a></span></span><span> </span><span id="local-6989586621680863859"><span class="annot"><span class="annottext">CoreArg
</span><a href="#local-6989586621680863859"><span class="hs-identifier hs-var">e</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Id -&gt; Bool
</span><a href="GHC.Types.Var.html#isId"><span class="hs-identifier hs-var">isId</span></a></span><span> </span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680863860"><span class="hs-identifier hs-var">x</span></a></span><span>           </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int -&gt; CoreArg -&gt; Bool
</span><a href="#local-6989586621680863863"><span class="hs-identifier hs-var">go</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863862"><span class="hs-identifier hs-var">credit</span></a></span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="../../base/src/GHC.Num.html#%2B"><span class="hs-operator hs-var">+</span></a></span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">1</span></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">CoreArg
</span><a href="#local-6989586621680863859"><span class="hs-identifier hs-var">e</span></a></span><span>
</span><span id="line-408"></span><span>                        </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span>        </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int -&gt; CoreArg -&gt; Bool
</span><a href="#local-6989586621680863863"><span class="hs-identifier hs-var">go</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863862"><span class="hs-identifier hs-var">credit</span></a></span><span> </span><span class="annot"><span class="annottext">CoreArg
</span><a href="#local-6989586621680863859"><span class="hs-identifier hs-var">e</span></a></span><span>
</span><span id="line-409"></span><span>        </span><span class="hs-comment">-- See Note [Count coercion arguments in boring contexts]</span><span>
</span><span id="line-410"></span><span>    </span><span class="annot"><a href="#local-6989586621680863863"><span class="hs-identifier hs-var">go</span></a></span><span> </span><span id="local-6989586621680863857"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863857"><span class="hs-identifier hs-var">credit</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#App"><span class="hs-identifier hs-type">App</span></a></span><span> </span><span id="local-6989586621680863855"><span class="annot"><span class="annottext">CoreArg
</span><a href="#local-6989586621680863855"><span class="hs-identifier hs-var">f</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#Type"><span class="hs-identifier hs-type">Type</span></a></span><span> </span><span class="hs-special">{</span><span class="hs-special">}</span><span class="hs-special">)</span><span class="hs-special">)</span><span>            </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int -&gt; CoreArg -&gt; Bool
</span><a href="#local-6989586621680863863"><span class="hs-identifier hs-var">go</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863857"><span class="hs-identifier hs-var">credit</span></a></span><span> </span><span class="annot"><span class="annottext">CoreArg
</span><a href="#local-6989586621680863855"><span class="hs-identifier hs-var">f</span></a></span><span>
</span><span id="line-411"></span><span>    </span><span class="annot"><a href="#local-6989586621680863863"><span class="hs-identifier hs-var">go</span></a></span><span> </span><span id="local-6989586621680863853"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863853"><span class="hs-identifier hs-var">credit</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#App"><span class="hs-identifier hs-type">App</span></a></span><span> </span><span id="local-6989586621680863852"><span class="annot"><span class="annottext">CoreArg
</span><a href="#local-6989586621680863852"><span class="hs-identifier hs-var">f</span></a></span></span><span> </span><span id="local-6989586621680863851"><span class="annot"><span class="annottext">CoreArg
</span><a href="#local-6989586621680863851"><span class="hs-identifier hs-var">a</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863853"><span class="hs-identifier hs-var">credit</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Bool
forall a. Ord a =&gt; a -&gt; a -&gt; Bool
</span><span class="hs-operator hs-var">&gt;</span></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">0</span></span><span>
</span><span id="line-412"></span><span>                        </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">CoreArg -&gt; Bool
</span><a href="GHC.Core.Utils.html#exprIsTrivial"><span class="hs-identifier hs-var">exprIsTrivial</span></a></span><span> </span><span class="annot"><span class="annottext">CoreArg
</span><a href="#local-6989586621680863851"><span class="hs-identifier hs-var">a</span></a></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int -&gt; CoreArg -&gt; Bool
</span><a href="#local-6989586621680863863"><span class="hs-identifier hs-var">go</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863853"><span class="hs-identifier hs-var">credit</span></a></span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="../../base/src/GHC.Num.html#-"><span class="hs-glyph hs-var">-</span></a></span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">1</span></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">CoreArg
</span><a href="#local-6989586621680863852"><span class="hs-identifier hs-var">f</span></a></span><span>
</span><span id="line-413"></span><span>    </span><span class="annot"><a href="#local-6989586621680863863"><span class="hs-identifier hs-var">go</span></a></span><span> </span><span id="local-6989586621680863848"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863848"><span class="hs-identifier hs-var">credit</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#Tick"><span class="hs-identifier hs-type">Tick</span></a></span><span> </span><span class="annot"><span class="annottext">Tickish Id
</span><span class="hs-identifier">_</span></span><span> </span><span id="local-6989586621680863846"><span class="annot"><span class="annottext">CoreArg
</span><a href="#local-6989586621680863846"><span class="hs-identifier hs-var">e</span></a></span></span><span class="hs-special">)</span><span>                   </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int -&gt; CoreArg -&gt; Bool
</span><a href="#local-6989586621680863863"><span class="hs-identifier hs-var">go</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863848"><span class="hs-identifier hs-var">credit</span></a></span><span> </span><span class="annot"><span class="annottext">CoreArg
</span><a href="#local-6989586621680863846"><span class="hs-identifier hs-var">e</span></a></span><span> </span><span class="hs-comment">-- dubious</span><span>
</span><span id="line-414"></span><span>    </span><span class="annot"><a href="#local-6989586621680863863"><span class="hs-identifier hs-var">go</span></a></span><span> </span><span id="local-6989586621680863845"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863845"><span class="hs-identifier hs-var">credit</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#Cast"><span class="hs-identifier hs-type">Cast</span></a></span><span> </span><span id="local-6989586621680863843"><span class="annot"><span class="annottext">CoreArg
</span><a href="#local-6989586621680863843"><span class="hs-identifier hs-var">e</span></a></span></span><span> </span><span class="annot"><span class="annottext">CoercionR
</span><span class="hs-identifier">_</span></span><span class="hs-special">)</span><span>                   </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int -&gt; CoreArg -&gt; Bool
</span><a href="#local-6989586621680863863"><span class="hs-identifier hs-var">go</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863845"><span class="hs-identifier hs-var">credit</span></a></span><span> </span><span class="annot"><span class="annottext">CoreArg
</span><a href="#local-6989586621680863843"><span class="hs-identifier hs-var">e</span></a></span><span>
</span><span id="line-415"></span><span>    </span><span class="annot"><a href="#local-6989586621680863863"><span class="hs-identifier hs-var">go</span></a></span><span> </span><span id="local-6989586621680863842"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863842"><span class="hs-identifier hs-var">credit</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#Case"><span class="hs-identifier hs-type">Case</span></a></span><span> </span><span id="local-6989586621680863840"><span class="annot"><span class="annottext">CoreArg
</span><a href="#local-6989586621680863840"><span class="hs-identifier hs-var">scrut</span></a></span></span><span> </span><span class="annot"><span class="annottext">Id
</span><span class="hs-identifier">_</span></span><span> </span><span class="annot"><span class="annottext">Type
</span><span class="hs-identifier">_</span></span><span> </span><span class="hs-special">[</span><span class="hs-special">(</span><span class="annot"><span class="annottext">AltCon
</span><span class="hs-identifier">_</span></span><span class="hs-special">,</span><span class="annot"><span class="annottext">[Id]
</span><span class="hs-identifier">_</span></span><span class="hs-special">,</span><span id="local-6989586621680863839"><span class="annot"><span class="annottext">CoreArg
</span><a href="#local-6989586621680863839"><span class="hs-identifier hs-var">rhs</span></a></span></span><span class="hs-special">)</span><span class="hs-special">]</span><span class="hs-special">)</span><span> </span><span class="hs-comment">-- See Note [Inline unsafeCoerce]</span><span>
</span><span id="line-416"></span><span>      </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">CoreArg -&gt; Bool
</span><a href="GHC.Core.Utils.html#isUnsafeEqualityProof"><span class="hs-identifier hs-var">isUnsafeEqualityProof</span></a></span><span> </span><span class="annot"><span class="annottext">CoreArg
</span><a href="#local-6989586621680863840"><span class="hs-identifier hs-var">scrut</span></a></span><span>        </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int -&gt; CoreArg -&gt; Bool
</span><a href="#local-6989586621680863863"><span class="hs-identifier hs-var">go</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863842"><span class="hs-identifier hs-var">credit</span></a></span><span> </span><span class="annot"><span class="annottext">CoreArg
</span><a href="#local-6989586621680863839"><span class="hs-identifier hs-var">rhs</span></a></span><span>
</span><span id="line-417"></span><span>    </span><span class="annot"><a href="#local-6989586621680863863"><span class="hs-identifier hs-var">go</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-identifier">_</span></span><span>      </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#Var"><span class="hs-identifier hs-type">Var</span></a></span><span> </span><span class="hs-special">{</span><span class="hs-special">}</span><span class="hs-special">)</span><span>                     </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="GHC.Core.html#boringCxtOk"><span class="hs-identifier hs-var">boringCxtOk</span></a></span><span>
</span><span id="line-418"></span><span>    </span><span class="annot"><a href="#local-6989586621680863863"><span class="hs-identifier hs-var">go</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-identifier">_</span></span><span>      </span><span class="annot"><span class="annottext">CoreArg
</span><span class="hs-identifier">_</span></span><span>                            </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="GHC.Core.html#boringCxtNotOk"><span class="hs-identifier hs-var">boringCxtNotOk</span></a></span><span>
</span><span id="line-419"></span><span>
</span><span id="line-420"></span><span class="annot"><a href="GHC.Core.Unfold.html#calcUnfoldingGuidance"><span class="hs-identifier hs-type">calcUnfoldingGuidance</span></a></span><span>
</span><span id="line-421"></span><span>        </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Driver.Session.html#DynFlags"><span class="hs-identifier hs-type">DynFlags</span></a></span><span>
</span><span id="line-422"></span><span>        </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Bool</span></span><span>          </span><span class="hs-comment">-- Definitely a top-level, bottoming binding</span><span>
</span><span id="line-423"></span><span>        </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.html#CoreExpr"><span class="hs-identifier hs-type">CoreExpr</span></a></span><span>      </span><span class="hs-comment">-- Expression to look at</span><span>
</span><span id="line-424"></span><span>        </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.html#UnfoldingGuidance"><span class="hs-identifier hs-type">UnfoldingGuidance</span></a></span><span>
</span><span id="line-425"></span><span id="calcUnfoldingGuidance"><span class="annot"><span class="annottext">calcUnfoldingGuidance :: DynFlags -&gt; Bool -&gt; CoreArg -&gt; UnfoldingGuidance
</span><a href="GHC.Core.Unfold.html#calcUnfoldingGuidance"><span class="hs-identifier hs-var hs-var">calcUnfoldingGuidance</span></a></span></span><span> </span><span id="local-6989586621680863836"><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680863836"><span class="hs-identifier hs-var">dflags</span></a></span></span><span> </span><span id="local-6989586621680863835"><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621680863835"><span class="hs-identifier hs-var">is_top_bottoming</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#Tick"><span class="hs-identifier hs-type">Tick</span></a></span><span> </span><span id="local-6989586621680863834"><span class="annot"><span class="annottext">Tickish Id
</span><a href="#local-6989586621680863834"><span class="hs-identifier hs-var">t</span></a></span></span><span> </span><span id="local-6989586621680863833"><span class="annot"><span class="annottext">CoreArg
</span><a href="#local-6989586621680863833"><span class="hs-identifier hs-var">expr</span></a></span></span><span class="hs-special">)</span><span>
</span><span id="line-426"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Bool
</span><span class="hs-identifier hs-var">not</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Tickish Id -&gt; Bool
forall id. Tickish id -&gt; Bool
</span><a href="GHC.Core.html#tickishIsCode"><span class="hs-identifier hs-var">tickishIsCode</span></a></span><span> </span><span class="annot"><span class="annottext">Tickish Id
</span><a href="#local-6989586621680863834"><span class="hs-identifier hs-var">t</span></a></span><span class="hs-special">)</span><span>  </span><span class="hs-comment">-- non-code ticks don't matter for unfolding</span><span>
</span><span id="line-427"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">DynFlags -&gt; Bool -&gt; CoreArg -&gt; UnfoldingGuidance
</span><a href="GHC.Core.Unfold.html#calcUnfoldingGuidance"><span class="hs-identifier hs-var">calcUnfoldingGuidance</span></a></span><span> </span><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680863836"><span class="hs-identifier hs-var">dflags</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621680863835"><span class="hs-identifier hs-var">is_top_bottoming</span></a></span><span> </span><span class="annot"><span class="annottext">CoreArg
</span><a href="#local-6989586621680863833"><span class="hs-identifier hs-var">expr</span></a></span><span>
</span><span id="line-428"></span><span class="annot"><a href="GHC.Core.Unfold.html#calcUnfoldingGuidance"><span class="hs-identifier hs-var">calcUnfoldingGuidance</span></a></span><span> </span><span id="local-6989586621680863831"><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680863831"><span class="hs-identifier hs-var">dflags</span></a></span></span><span> </span><span id="local-6989586621680863830"><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621680863830"><span class="hs-identifier hs-var">is_top_bottoming</span></a></span></span><span> </span><span id="local-6989586621680863829"><span class="annot"><span class="annottext">CoreArg
</span><a href="#local-6989586621680863829"><span class="hs-identifier hs-var">expr</span></a></span></span><span>
</span><span id="line-429"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">DynFlags -&gt; Int -&gt; [Id] -&gt; CoreArg -&gt; ExprSize
</span><a href="GHC.Core.Unfold.html#sizeExpr"><span class="hs-identifier hs-var">sizeExpr</span></a></span><span> </span><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680863831"><span class="hs-identifier hs-var">dflags</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863827"><span class="hs-identifier hs-var">bOMB_OUT_SIZE</span></a></span><span> </span><span class="annot"><span class="annottext">[Id]
</span><a href="#local-6989586621680863826"><span class="hs-identifier hs-var">val_bndrs</span></a></span><span> </span><span class="annot"><span class="annottext">CoreArg
</span><a href="#local-6989586621680863825"><span class="hs-identifier hs-var">body</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-430"></span><span>      </span><span class="annot"><span class="annottext">ExprSize
</span><a href="GHC.Core.Unfold.html#TooBig"><span class="hs-identifier hs-var">TooBig</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">UnfoldingGuidance
</span><a href="GHC.Core.html#UnfNever"><span class="hs-identifier hs-var">UnfNever</span></a></span><span>
</span><span id="line-431"></span><span>      </span><span class="annot"><a href="GHC.Core.Unfold.html#SizeIs"><span class="hs-identifier hs-type">SizeIs</span></a></span><span> </span><span id="local-6989586621680863821"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863821"><span class="hs-identifier hs-var">size</span></a></span></span><span> </span><span id="local-6989586621680863820"><span class="annot"><span class="annottext">Bag (Id, Int)
</span><a href="#local-6989586621680863820"><span class="hs-identifier hs-var">cased_bndrs</span></a></span></span><span> </span><span id="local-6989586621680863819"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863819"><span class="hs-identifier hs-var">scrut_discount</span></a></span></span><span>
</span><span id="line-432"></span><span>        </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">CoreArg -&gt; Int -&gt; Int -&gt; Bool
</span><a href="GHC.Core.Unfold.html#uncondInline"><span class="hs-identifier hs-var">uncondInline</span></a></span><span> </span><span class="annot"><span class="annottext">CoreArg
</span><a href="#local-6989586621680863829"><span class="hs-identifier hs-var">expr</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863817"><span class="hs-identifier hs-var">n_val_bndrs</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863821"><span class="hs-identifier hs-var">size</span></a></span><span>
</span><span id="line-433"></span><span>        </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">UnfWhen :: Int -&gt; Bool -&gt; Bool -&gt; UnfoldingGuidance
</span><a href="GHC.Core.html#UnfWhen"><span class="hs-identifier hs-type">UnfWhen</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">ug_unsat_ok :: Bool
</span><a href="GHC.Core.html#ug_unsat_ok"><span class="hs-identifier hs-var">ug_unsat_ok</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="GHC.Core.html#unSaturatedOk"><span class="hs-identifier hs-var">unSaturatedOk</span></a></span><span>
</span><span id="line-434"></span><span>                   </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">ug_boring_ok :: Bool
</span><a href="GHC.Core.html#ug_boring_ok"><span class="hs-identifier hs-var">ug_boring_ok</span></a></span><span> </span><span class="hs-glyph">=</span><span>  </span><span class="annot"><span class="annottext">Bool
</span><a href="GHC.Core.html#boringCxtOk"><span class="hs-identifier hs-var">boringCxtOk</span></a></span><span>
</span><span id="line-435"></span><span>                   </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">ug_arity :: Int
</span><a href="GHC.Core.html#ug_arity"><span class="hs-identifier hs-var">ug_arity</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863817"><span class="hs-identifier hs-var">n_val_bndrs</span></a></span><span> </span><span class="hs-special">}</span><span>   </span><span class="hs-comment">-- Note [INLINE for small functions]</span><span>
</span><span id="line-436"></span><span>
</span><span id="line-437"></span><span>        </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621680863830"><span class="hs-identifier hs-var">is_top_bottoming</span></a></span><span>
</span><span id="line-438"></span><span>        </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">UnfoldingGuidance
</span><a href="GHC.Core.html#UnfNever"><span class="hs-identifier hs-var">UnfNever</span></a></span><span>   </span><span class="hs-comment">-- See Note [Do not inline top-level bottoming functions]</span><span>
</span><span id="line-439"></span><span>
</span><span id="line-440"></span><span>        </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span>
</span><span id="line-441"></span><span>        </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">UnfIfGoodArgs :: [Int] -&gt; Int -&gt; Int -&gt; UnfoldingGuidance
</span><a href="GHC.Core.html#UnfIfGoodArgs"><span class="hs-identifier hs-type">UnfIfGoodArgs</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">ug_args :: [Int]
</span><a href="GHC.Core.html#ug_args"><span class="hs-identifier hs-var">ug_args</span></a></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(Id -&gt; Int) -&gt; [Id] -&gt; [Int]
forall a b. (a -&gt; b) -&gt; [a] -&gt; [b]
</span><a href="../../base/src/GHC.Base.html#map"><span class="hs-identifier hs-var">map</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Bag (Id, Int) -&gt; Id -&gt; Int
</span><a href="#local-6989586621680863814"><span class="hs-identifier hs-var">mk_discount</span></a></span><span> </span><span class="annot"><span class="annottext">Bag (Id, Int)
</span><a href="#local-6989586621680863820"><span class="hs-identifier hs-var">cased_bndrs</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">[Id]
</span><a href="#local-6989586621680863826"><span class="hs-identifier hs-var">val_bndrs</span></a></span><span>
</span><span id="line-442"></span><span>                         </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">ug_size :: Int
</span><a href="GHC.Core.html#ug_size"><span class="hs-identifier hs-var">ug_size</span></a></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863821"><span class="hs-identifier hs-var">size</span></a></span><span>
</span><span id="line-443"></span><span>                         </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">ug_res :: Int
</span><a href="GHC.Core.html#ug_res"><span class="hs-identifier hs-var">ug_res</span></a></span><span>   </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863819"><span class="hs-identifier hs-var">scrut_discount</span></a></span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-444"></span><span>
</span><span id="line-445"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-446"></span><span>    </span><span class="hs-special">(</span><span id="local-6989586621680863811"><span class="annot"><span class="annottext">[Id]
</span><a href="#local-6989586621680863811"><span class="hs-identifier hs-var">bndrs</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621680863825"><span class="annot"><span class="annottext">CoreArg
</span><a href="#local-6989586621680863825"><span class="hs-identifier hs-var">body</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">CoreArg -&gt; ([Id], CoreArg)
forall b. Expr b -&gt; ([b], Expr b)
</span><a href="GHC.Core.html#collectBinders"><span class="hs-identifier hs-var">collectBinders</span></a></span><span> </span><span class="annot"><span class="annottext">CoreArg
</span><a href="#local-6989586621680863829"><span class="hs-identifier hs-var">expr</span></a></span><span>
</span><span id="line-447"></span><span>    </span><span id="local-6989586621680863827"><span class="annot"><span class="annottext">bOMB_OUT_SIZE :: Int
</span><a href="#local-6989586621680863827"><span class="hs-identifier hs-var hs-var">bOMB_OUT_SIZE</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">DynFlags -&gt; Int
</span><a href="GHC.Driver.Session.html#ufCreationThreshold"><span class="hs-identifier hs-var hs-var">ufCreationThreshold</span></a></span><span> </span><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680863831"><span class="hs-identifier hs-var">dflags</span></a></span><span>
</span><span id="line-448"></span><span>           </span><span class="hs-comment">-- Bomb out if size gets bigger than this</span><span>
</span><span id="line-449"></span><span>    </span><span id="local-6989586621680863826"><span class="annot"><span class="annottext">val_bndrs :: [Id]
</span><a href="#local-6989586621680863826"><span class="hs-identifier hs-var hs-var">val_bndrs</span></a></span></span><span>   </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(Id -&gt; Bool) -&gt; [Id] -&gt; [Id]
forall a. (a -&gt; Bool) -&gt; [a] -&gt; [a]
</span><a href="../../base/src/GHC.List.html#filter"><span class="hs-identifier hs-var">filter</span></a></span><span> </span><span class="annot"><span class="annottext">Id -&gt; Bool
</span><a href="GHC.Types.Var.html#isId"><span class="hs-identifier hs-var">isId</span></a></span><span> </span><span class="annot"><span class="annottext">[Id]
</span><a href="#local-6989586621680863811"><span class="hs-identifier hs-var">bndrs</span></a></span><span>
</span><span id="line-450"></span><span>    </span><span id="local-6989586621680863817"><span class="annot"><span class="annottext">n_val_bndrs :: Int
</span><a href="#local-6989586621680863817"><span class="hs-identifier hs-var hs-var">n_val_bndrs</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[Id] -&gt; Int
forall (t :: * -&gt; *) a. Foldable t =&gt; t a -&gt; Int
</span><a href="../../base/src/Data.Foldable.html#length"><span class="hs-identifier hs-var">length</span></a></span><span> </span><span class="annot"><span class="annottext">[Id]
</span><a href="#local-6989586621680863826"><span class="hs-identifier hs-var">val_bndrs</span></a></span><span>
</span><span id="line-451"></span><span>
</span><span id="line-452"></span><span>    </span><span class="annot"><a href="#local-6989586621680863814"><span class="hs-identifier hs-type">mk_discount</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Data.Bag.html#Bag"><span class="hs-identifier hs-type">Bag</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Types.Var.html#Id"><span class="hs-identifier hs-type">Id</span></a></span><span class="hs-special">,</span><span class="annot"><span class="hs-identifier hs-type">Int</span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Types.Var.html#Id"><span class="hs-identifier hs-type">Id</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Int</span></span><span>
</span><span id="line-453"></span><span>    </span><span id="local-6989586621680863814"><span class="annot"><span class="annottext">mk_discount :: Bag (Id, Int) -&gt; Id -&gt; Int
</span><a href="#local-6989586621680863814"><span class="hs-identifier hs-var hs-var">mk_discount</span></a></span></span><span> </span><span id="local-6989586621680863806"><span class="annot"><span class="annottext">Bag (Id, Int)
</span><a href="#local-6989586621680863806"><span class="hs-identifier hs-var">cbs</span></a></span></span><span> </span><span id="local-6989586621680863805"><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680863805"><span class="hs-identifier hs-var">bndr</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(Int -&gt; (Id, Int) -&gt; Int) -&gt; Int -&gt; Bag (Id, Int) -&gt; Int
forall (t :: * -&gt; *) b a.
Foldable t =&gt;
(b -&gt; a -&gt; b) -&gt; b -&gt; t a -&gt; b
</span><a href="../../base/src/Data.Foldable.html#foldl%27"><span class="hs-identifier hs-var">foldl'</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; (Id, Int) -&gt; Int
</span><a href="#local-6989586621680863803"><span class="hs-identifier hs-var">combine</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">0</span></span><span> </span><span class="annot"><span class="annottext">Bag (Id, Int)
</span><a href="#local-6989586621680863806"><span class="hs-identifier hs-var">cbs</span></a></span><span>
</span><span id="line-454"></span><span>           </span><span class="hs-keyword">where</span><span>
</span><span id="line-455"></span><span>             </span><span id="local-6989586621680863803"><span class="annot"><span class="annottext">combine :: Int -&gt; (Id, Int) -&gt; Int
</span><a href="#local-6989586621680863803"><span class="hs-identifier hs-var hs-var">combine</span></a></span></span><span> </span><span id="local-6989586621680863800"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863800"><span class="hs-identifier hs-var">acc</span></a></span></span><span> </span><span class="hs-special">(</span><span id="local-6989586621680863799"><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680863799"><span class="hs-identifier hs-var">bndr'</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621680863798"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863798"><span class="hs-identifier hs-var">disc</span></a></span></span><span class="hs-special">)</span><span>
</span><span id="line-456"></span><span>               </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680863805"><span class="hs-identifier hs-var">bndr</span></a></span><span> </span><span class="annot"><span class="annottext">Id -&gt; Id -&gt; Bool
forall a. Eq a =&gt; a -&gt; a -&gt; Bool
</span><span class="hs-operator hs-var">==</span></span><span> </span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680863799"><span class="hs-identifier hs-var">bndr'</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863800"><span class="hs-identifier hs-var">acc</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
</span><a href="#local-6989586621680863797"><span class="hs-operator hs-var">`plus_disc`</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863798"><span class="hs-identifier hs-var">disc</span></a></span><span>
</span><span id="line-457"></span><span>               </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span>     </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863800"><span class="hs-identifier hs-var">acc</span></a></span><span>
</span><span id="line-458"></span><span>
</span><span id="line-459"></span><span>             </span><span class="annot"><a href="#local-6989586621680863797"><span class="hs-identifier hs-type">plus_disc</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Int</span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Int</span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Int</span></span><span>
</span><span id="line-460"></span><span>             </span><span id="local-6989586621680863797"><span class="annot"><span class="annottext">plus_disc :: Int -&gt; Int -&gt; Int
</span><a href="#local-6989586621680863797"><span class="hs-identifier hs-var hs-var">plus_disc</span></a></span></span><span> </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Type -&gt; Bool
</span><a href="GHC.Core.Type.html#isFunTy"><span class="hs-identifier hs-var">isFunTy</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Id -&gt; Type
</span><a href="GHC.Types.Id.html#idType"><span class="hs-identifier hs-var">idType</span></a></span><span> </span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680863805"><span class="hs-identifier hs-var">bndr</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Ord a =&gt; a -&gt; a -&gt; a
</span><span class="hs-identifier hs-var">max</span></span><span>
</span><span id="line-461"></span><span>                       </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span>             </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="../../base/src/GHC.Num.html#%2B"><span class="hs-operator hs-var">(+)</span></a></span><span>
</span><span id="line-462"></span><span>             </span><span class="hs-comment">-- See Note [Function and non-function discounts]</span><span>
</span><span id="line-463"></span><span>
</span><span id="line-464"></span><span class="hs-comment">{- Note [Inline unsafeCoerce]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
We really want to inline unsafeCoerce, even when applied to boring
arguments.  It doesn't look as if its RHS is smaller than the call
   unsafeCoerce x = case unsafeEqualityProof @a @b of UnsafeRefl -&gt; x
but that case is discarded -- see Note [Implementing unsafeCoerce]
in base:Unsafe.Coerce.

Moreover, if we /don't/ inline it, we may be left with
          f (unsafeCoerce x)
which will build a thunk -- bad, bad, bad.

Conclusion: we really want inlineBoringOk to be True of the RHS of
unsafeCoerce.  This is (U4) in Note [Implementing unsafeCoerce].

Note [Computing the size of an expression]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The basic idea of sizeExpr is obvious enough: count nodes.  But getting the
heuristics right has taken a long time.  Here's the basic strategy:

    * Variables, literals: 0
      (Exception for string literals, see litSize.)

    * Function applications (f e1 .. en): 1 + #value args

    * Constructor applications: 1, regardless of #args

    * Let(rec): 1 + size of components

    * Note, cast: 0

Examples

  Size  Term
  --------------
    0     42#
    0     x
    0     True
    2     f x
    1     Just x
    4     f (g x)

Notice that 'x' counts 0, while (f x) counts 2.  That's deliberate: there's
a function call to account for.  Notice also that constructor applications
are very cheap, because exposing them to a caller is so valuable.

[25/5/11] All sizes are now multiplied by 10, except for primops
(which have sizes like 1 or 4.  This makes primops look fantastically
cheap, and seems to be almost universally beneficial.  Done partly as a
result of #4978.

Note [Do not inline top-level bottoming functions]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The FloatOut pass has gone to some trouble to float out calls to 'error'
and similar friends.  See Note [Bottoming floats] in GHC.Core.Opt.SetLevels.
Do not re-inline them!  But we *do* still inline if they are very small
(the uncondInline stuff).

Note [INLINE for small functions]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Consider        {-# INLINE f #-}
                f x = Just x
                g y = f y
Then f's RHS is no larger than its LHS, so we should inline it into
even the most boring context.  In general, f the function is
sufficiently small that its body is as small as the call itself, the
inline unconditionally, regardless of how boring the context is.

Things to note:

(1) We inline *unconditionally* if inlined thing is smaller (using sizeExpr)
    than the thing it's replacing.  Notice that
      (f x) --&gt; (g 3)             -- YES, unconditionally
      (f x) --&gt; x : []            -- YES, *even though* there are two
                                  --      arguments to the cons
      x     --&gt; g 3               -- NO
      x     --&gt; Just v            -- NO

    It's very important not to unconditionally replace a variable by
    a non-atomic term.

(2) We do this even if the thing isn't saturated, else we end up with the
    silly situation that
       f x y = x
       ...map (f 3)...
    doesn't inline.  Even in a boring context, inlining without being
    saturated will give a lambda instead of a PAP, and will be more
    efficient at runtime.

(3) However, when the function's arity &gt; 0, we do insist that it
    has at least one value argument at the call site.  (This check is
    made in the UnfWhen case of callSiteInline.) Otherwise we find this:
         f = /\a \x:a. x
         d = /\b. MkD (f b)
    If we inline f here we get
         d = /\b. MkD (\x:b. x)
    and then prepareRhs floats out the argument, abstracting the type
    variables, so we end up with the original again!

(4) We must be much more cautious about arity-zero things. Consider
       let x = y +# z in ...
    In *size* terms primops look very small, because the generate a
    single instruction, but we do not want to unconditionally replace
    every occurrence of x with (y +# z).  So we only do the
    unconditional-inline thing for *trivial* expressions.

    NB: you might think that PostInlineUnconditionally would do this
    but it doesn't fire for top-level things; see GHC.Core.Opt.Simplify.Utils
    Note [Top level and postInlineUnconditionally]

Note [Count coercion arguments in boring contexts]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In inlineBoringOK, we ignore type arguments when deciding whether an
expression is okay to inline into boring contexts. This is good, since
if we have a definition like

  let y = x @Int in f y y

there&#8217;s no reason not to inline y at both use sites &#8212; no work is
actually duplicated. It may seem like the same reasoning applies to
coercion arguments, and indeed, in #17182 we changed inlineBoringOK to
treat coercions the same way.

However, this isn&#8217;t a good idea: unlike type arguments, which have
no runtime representation, coercion arguments *do* have a runtime
representation (albeit the zero-width VoidRep, see Note [Coercion tokens]
in &quot;GHC.CoreToStg&quot;). This caused trouble in #17787 for DataCon wrappers for
nullary GADT constructors: the wrappers would be inlined and each use of
the constructor would lead to a separate allocation instead of just
sharing the wrapper closure.

The solution: don&#8217;t ignore coercion arguments after all.
-}</span><span>
</span><span id="line-597"></span><span>
</span><span id="line-598"></span><span class="annot"><a href="GHC.Core.Unfold.html#uncondInline"><span class="hs-identifier hs-type">uncondInline</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.html#CoreExpr"><span class="hs-identifier hs-type">CoreExpr</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Types.Basic.html#Arity"><span class="hs-identifier hs-type">Arity</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Int</span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Bool</span></span><span>
</span><span id="line-599"></span><span class="hs-comment">-- Inline unconditionally if there no size increase</span><span>
</span><span id="line-600"></span><span class="hs-comment">-- Size of call is arity (+1 for the function)</span><span>
</span><span id="line-601"></span><span class="hs-comment">-- See Note [INLINE for small functions]</span><span>
</span><span id="line-602"></span><span id="uncondInline"><span class="annot"><span class="annottext">uncondInline :: CoreArg -&gt; Int -&gt; Int -&gt; Bool
</span><a href="GHC.Core.Unfold.html#uncondInline"><span class="hs-identifier hs-var hs-var">uncondInline</span></a></span></span><span> </span><span id="local-6989586621680863793"><span class="annot"><span class="annottext">CoreArg
</span><a href="#local-6989586621680863793"><span class="hs-identifier hs-var">rhs</span></a></span></span><span> </span><span id="local-6989586621680863792"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863792"><span class="hs-identifier hs-var">arity</span></a></span></span><span> </span><span id="local-6989586621680863791"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863791"><span class="hs-identifier hs-var">size</span></a></span></span><span>
</span><span id="line-603"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863792"><span class="hs-identifier hs-var">arity</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Bool
forall a. Ord a =&gt; a -&gt; a -&gt; Bool
</span><span class="hs-operator hs-var">&gt;</span></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">0</span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863791"><span class="hs-identifier hs-var">size</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Bool
forall a. Ord a =&gt; a -&gt; a -&gt; Bool
</span><span class="hs-operator hs-var">&lt;=</span></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">10</span></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="../../base/src/GHC.Num.html#%2A"><span class="hs-operator hs-var">*</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863792"><span class="hs-identifier hs-var">arity</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="../../base/src/GHC.Num.html#%2B"><span class="hs-operator hs-var">+</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">1</span></span><span class="hs-special">)</span><span> </span><span class="hs-comment">-- See Note [INLINE for small functions] (1)</span><span>
</span><span id="line-604"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">CoreArg -&gt; Bool
</span><a href="GHC.Core.Utils.html#exprIsTrivial"><span class="hs-identifier hs-var">exprIsTrivial</span></a></span><span> </span><span class="annot"><span class="annottext">CoreArg
</span><a href="#local-6989586621680863793"><span class="hs-identifier hs-var">rhs</span></a></span><span>        </span><span class="hs-comment">-- See Note [INLINE for small functions] (4)</span><span>
</span><span id="line-605"></span><span>
</span><span id="line-606"></span><span class="annot"><a href="GHC.Core.Unfold.html#sizeExpr"><span class="hs-identifier hs-type">sizeExpr</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Driver.Session.html#DynFlags"><span class="hs-identifier hs-type">DynFlags</span></a></span><span>
</span><span id="line-607"></span><span>         </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Int</span></span><span>             </span><span class="hs-comment">-- Bomb out if it gets bigger than this</span><span>
</span><span id="line-608"></span><span>         </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Types.Var.html#Id"><span class="hs-identifier hs-type">Id</span></a></span><span class="hs-special">]</span><span>            </span><span class="hs-comment">-- Arguments; we're interested in which of these</span><span>
</span><span id="line-609"></span><span>                            </span><span class="hs-comment">-- get case'd</span><span>
</span><span id="line-610"></span><span>         </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.html#CoreExpr"><span class="hs-identifier hs-type">CoreExpr</span></a></span><span>
</span><span id="line-611"></span><span>         </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.Unfold.html#ExprSize"><span class="hs-identifier hs-type">ExprSize</span></a></span><span>
</span><span id="line-612"></span><span>
</span><span id="line-613"></span><span class="hs-comment">-- Note [Computing the size of an expression]</span><span>
</span><span id="line-614"></span><span>
</span><span id="line-615"></span><span id="sizeExpr"><span class="annot"><span class="annottext">sizeExpr :: DynFlags -&gt; Int -&gt; [Id] -&gt; CoreArg -&gt; ExprSize
</span><a href="GHC.Core.Unfold.html#sizeExpr"><span class="hs-identifier hs-var hs-var">sizeExpr</span></a></span></span><span> </span><span id="local-6989586621680863788"><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680863788"><span class="hs-identifier hs-var">dflags</span></a></span></span><span> </span><span id="local-6989586621680863787"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863787"><span class="hs-identifier hs-var">bOMB_OUT_SIZE</span></a></span></span><span> </span><span id="local-6989586621680863786"><span class="annot"><span class="annottext">[Id]
</span><a href="#local-6989586621680863786"><span class="hs-identifier hs-var">top_args</span></a></span></span><span> </span><span id="local-6989586621680863785"><span class="annot"><span class="annottext">CoreArg
</span><a href="#local-6989586621680863785"><span class="hs-identifier hs-var">expr</span></a></span></span><span>
</span><span id="line-616"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">CoreArg -&gt; ExprSize
</span><a href="#local-6989586621680863784"><span class="hs-identifier hs-var">size_up</span></a></span><span> </span><span class="annot"><span class="annottext">CoreArg
</span><a href="#local-6989586621680863785"><span class="hs-identifier hs-var">expr</span></a></span><span>
</span><span id="line-617"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-618"></span><span>    </span><span id="local-6989586621680863784"><span class="annot"><span class="annottext">size_up :: CoreArg -&gt; ExprSize
</span><a href="#local-6989586621680863784"><span class="hs-identifier hs-var hs-var">size_up</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#Cast"><span class="hs-identifier hs-type">Cast</span></a></span><span> </span><span id="local-6989586621680863769"><span class="annot"><span class="annottext">CoreArg
</span><a href="#local-6989586621680863769"><span class="hs-identifier hs-var">e</span></a></span></span><span> </span><span class="annot"><span class="annottext">CoercionR
</span><span class="hs-identifier">_</span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">CoreArg -&gt; ExprSize
</span><a href="#local-6989586621680863784"><span class="hs-identifier hs-var">size_up</span></a></span><span> </span><span class="annot"><span class="annottext">CoreArg
</span><a href="#local-6989586621680863769"><span class="hs-identifier hs-var">e</span></a></span><span>
</span><span id="line-619"></span><span>    </span><span class="annot"><a href="#local-6989586621680863784"><span class="hs-identifier hs-var">size_up</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#Tick"><span class="hs-identifier hs-type">Tick</span></a></span><span> </span><span class="annot"><span class="annottext">Tickish Id
</span><span class="hs-identifier">_</span></span><span> </span><span id="local-6989586621680863768"><span class="annot"><span class="annottext">CoreArg
</span><a href="#local-6989586621680863768"><span class="hs-identifier hs-var">e</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">CoreArg -&gt; ExprSize
</span><a href="#local-6989586621680863784"><span class="hs-identifier hs-var">size_up</span></a></span><span> </span><span class="annot"><span class="annottext">CoreArg
</span><a href="#local-6989586621680863768"><span class="hs-identifier hs-var">e</span></a></span><span>
</span><span id="line-620"></span><span>    </span><span class="annot"><a href="#local-6989586621680863784"><span class="hs-identifier hs-var">size_up</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#Type"><span class="hs-identifier hs-type">Type</span></a></span><span> </span><span class="annot"><span class="annottext">Type
</span><span class="hs-identifier">_</span></span><span class="hs-special">)</span><span>   </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">ExprSize
</span><a href="GHC.Core.Unfold.html#sizeZero"><span class="hs-identifier hs-var">sizeZero</span></a></span><span>           </span><span class="hs-comment">-- Types cost nothing</span><span>
</span><span id="line-621"></span><span>    </span><span class="annot"><a href="#local-6989586621680863784"><span class="hs-identifier hs-var">size_up</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#Coercion"><span class="hs-identifier hs-type">Coercion</span></a></span><span> </span><span class="annot"><span class="annottext">CoercionR
</span><span class="hs-identifier">_</span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">ExprSize
</span><a href="GHC.Core.Unfold.html#sizeZero"><span class="hs-identifier hs-var">sizeZero</span></a></span><span>
</span><span id="line-622"></span><span>    </span><span class="annot"><a href="#local-6989586621680863784"><span class="hs-identifier hs-var">size_up</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#Lit"><span class="hs-identifier hs-type">Lit</span></a></span><span> </span><span id="local-6989586621680863764"><span class="annot"><span class="annottext">Literal
</span><a href="#local-6989586621680863764"><span class="hs-identifier hs-var">lit</span></a></span></span><span class="hs-special">)</span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int -&gt; ExprSize
</span><a href="GHC.Core.Unfold.html#sizeN"><span class="hs-identifier hs-var">sizeN</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Literal -&gt; Int
</span><a href="GHC.Core.Unfold.html#litSize"><span class="hs-identifier hs-var">litSize</span></a></span><span> </span><span class="annot"><span class="annottext">Literal
</span><a href="#local-6989586621680863764"><span class="hs-identifier hs-var">lit</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-623"></span><span>    </span><span class="annot"><a href="#local-6989586621680863784"><span class="hs-identifier hs-var">size_up</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#Var"><span class="hs-identifier hs-type">Var</span></a></span><span> </span><span id="local-6989586621680863761"><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680863761"><span class="hs-identifier hs-var">f</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Id -&gt; Bool
</span><a href="#local-6989586621680863760"><span class="hs-identifier hs-var">isRealWorldId</span></a></span><span> </span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680863761"><span class="hs-identifier hs-var">f</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">ExprSize
</span><a href="GHC.Core.Unfold.html#sizeZero"><span class="hs-identifier hs-var">sizeZero</span></a></span><span>
</span><span id="line-624"></span><span>                      </span><span class="hs-comment">-- Make sure we get constructor discounts even</span><span>
</span><span id="line-625"></span><span>                      </span><span class="hs-comment">-- on nullary constructors</span><span>
</span><span id="line-626"></span><span>                    </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span>       </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Id -&gt; [CoreArg] -&gt; Int -&gt; ExprSize
</span><a href="#local-6989586621680863759"><span class="hs-identifier hs-var">size_up_call</span></a></span><span> </span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680863761"><span class="hs-identifier hs-var">f</span></a></span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">0</span></span><span>
</span><span id="line-627"></span><span>
</span><span id="line-628"></span><span>    </span><span class="annot"><a href="#local-6989586621680863784"><span class="hs-identifier hs-var">size_up</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#App"><span class="hs-identifier hs-type">App</span></a></span><span> </span><span id="local-6989586621680863758"><span class="annot"><span class="annottext">CoreArg
</span><a href="#local-6989586621680863758"><span class="hs-identifier hs-var">fun</span></a></span></span><span> </span><span id="local-6989586621680863757"><span class="annot"><span class="annottext">CoreArg
</span><a href="#local-6989586621680863757"><span class="hs-identifier hs-var">arg</span></a></span></span><span class="hs-special">)</span><span>
</span><span id="line-629"></span><span>      </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">CoreArg -&gt; Bool
forall b. Expr b -&gt; Bool
</span><a href="GHC.Core.html#isTyCoArg"><span class="hs-identifier hs-var">isTyCoArg</span></a></span><span> </span><span class="annot"><span class="annottext">CoreArg
</span><a href="#local-6989586621680863757"><span class="hs-identifier hs-var">arg</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">CoreArg -&gt; ExprSize
</span><a href="#local-6989586621680863784"><span class="hs-identifier hs-var">size_up</span></a></span><span> </span><span class="annot"><span class="annottext">CoreArg
</span><a href="#local-6989586621680863758"><span class="hs-identifier hs-var">fun</span></a></span><span>
</span><span id="line-630"></span><span>      </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span>     </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">CoreArg -&gt; ExprSize
</span><a href="#local-6989586621680863784"><span class="hs-identifier hs-var">size_up</span></a></span><span> </span><span class="annot"><span class="annottext">CoreArg
</span><a href="#local-6989586621680863757"><span class="hs-identifier hs-var">arg</span></a></span><span>  </span><span class="annot"><span class="annottext">ExprSize -&gt; ExprSize -&gt; ExprSize
</span><a href="#local-6989586621680863755"><span class="hs-operator hs-var">`addSizeNSD`</span></a></span><span>
</span><span id="line-631"></span><span>                        </span><span class="annot"><span class="annottext">CoreArg -&gt; [CoreArg] -&gt; Int -&gt; ExprSize
</span><a href="#local-6989586621680863754"><span class="hs-identifier hs-var">size_up_app</span></a></span><span> </span><span class="annot"><span class="annottext">CoreArg
</span><a href="#local-6989586621680863758"><span class="hs-identifier hs-var">fun</span></a></span><span> </span><span class="hs-special">[</span><span class="annot"><span class="annottext">CoreArg
</span><a href="#local-6989586621680863757"><span class="hs-identifier hs-var">arg</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-special">(</span><span class="hs-keyword">if</span><span> </span><span class="annot"><span class="annottext">CoreArg -&gt; Bool
forall b. Expr b -&gt; Bool
</span><a href="#local-6989586621680863753"><span class="hs-identifier hs-var">isRealWorldExpr</span></a></span><span> </span><span class="annot"><span class="annottext">CoreArg
</span><a href="#local-6989586621680863757"><span class="hs-identifier hs-var">arg</span></a></span><span> </span><span class="hs-keyword">then</span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">1</span></span><span> </span><span class="hs-keyword">else</span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">0</span></span><span class="hs-special">)</span><span>
</span><span id="line-632"></span><span>
</span><span id="line-633"></span><span>    </span><span class="annot"><a href="#local-6989586621680863784"><span class="hs-identifier hs-var">size_up</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#Lam"><span class="hs-identifier hs-type">Lam</span></a></span><span> </span><span id="local-6989586621680863752"><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680863752"><span class="hs-identifier hs-var">b</span></a></span></span><span> </span><span id="local-6989586621680863751"><span class="annot"><span class="annottext">CoreArg
</span><a href="#local-6989586621680863751"><span class="hs-identifier hs-var">e</span></a></span></span><span class="hs-special">)</span><span>
</span><span id="line-634"></span><span>      </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Id -&gt; Bool
</span><a href="GHC.Types.Var.html#isId"><span class="hs-identifier hs-var">isId</span></a></span><span> </span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680863752"><span class="hs-identifier hs-var">b</span></a></span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Bool -&gt; Bool
</span><span class="hs-operator hs-var">&amp;&amp;</span></span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Bool
</span><span class="hs-identifier hs-var">not</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Id -&gt; Bool
</span><a href="#local-6989586621680863760"><span class="hs-identifier hs-var">isRealWorldId</span></a></span><span> </span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680863752"><span class="hs-identifier hs-var">b</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">DynFlags -&gt; ExprSize -&gt; ExprSize
</span><a href="GHC.Core.Unfold.html#lamScrutDiscount"><span class="hs-identifier hs-var">lamScrutDiscount</span></a></span><span> </span><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680863788"><span class="hs-identifier hs-var">dflags</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">CoreArg -&gt; ExprSize
</span><a href="#local-6989586621680863784"><span class="hs-identifier hs-var">size_up</span></a></span><span> </span><span class="annot"><span class="annottext">CoreArg
</span><a href="#local-6989586621680863751"><span class="hs-identifier hs-var">e</span></a></span><span> </span><span class="annot"><span class="annottext">ExprSize -&gt; Int -&gt; ExprSize
</span><a href="#local-6989586621680863749"><span class="hs-operator hs-var">`addSizeN`</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">10</span></span><span class="hs-special">)</span><span>
</span><span id="line-635"></span><span>      </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">CoreArg -&gt; ExprSize
</span><a href="#local-6989586621680863784"><span class="hs-identifier hs-var">size_up</span></a></span><span> </span><span class="annot"><span class="annottext">CoreArg
</span><a href="#local-6989586621680863751"><span class="hs-identifier hs-var">e</span></a></span><span>
</span><span id="line-636"></span><span>
</span><span id="line-637"></span><span>    </span><span class="annot"><a href="#local-6989586621680863784"><span class="hs-identifier hs-var">size_up</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#Let"><span class="hs-identifier hs-type">Let</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#NonRec"><span class="hs-identifier hs-type">NonRec</span></a></span><span> </span><span id="local-6989586621680863746"><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680863746"><span class="hs-identifier hs-var">binder</span></a></span></span><span> </span><span id="local-6989586621680863745"><span class="annot"><span class="annottext">CoreArg
</span><a href="#local-6989586621680863745"><span class="hs-identifier hs-var">rhs</span></a></span></span><span class="hs-special">)</span><span> </span><span id="local-6989586621680863744"><span class="annot"><span class="annottext">CoreArg
</span><a href="#local-6989586621680863744"><span class="hs-identifier hs-var">body</span></a></span></span><span class="hs-special">)</span><span>
</span><span id="line-638"></span><span>      </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(Id, CoreArg) -&gt; ExprSize
</span><a href="#local-6989586621680863743"><span class="hs-identifier hs-var">size_up_rhs</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680863746"><span class="hs-identifier hs-var">binder</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">CoreArg
</span><a href="#local-6989586621680863745"><span class="hs-identifier hs-var">rhs</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">ExprSize -&gt; ExprSize -&gt; ExprSize
</span><a href="#local-6989586621680863755"><span class="hs-operator hs-var">`addSizeNSD`</span></a></span><span>
</span><span id="line-639"></span><span>        </span><span class="annot"><span class="annottext">CoreArg -&gt; ExprSize
</span><a href="#local-6989586621680863784"><span class="hs-identifier hs-var">size_up</span></a></span><span> </span><span class="annot"><span class="annottext">CoreArg
</span><a href="#local-6989586621680863744"><span class="hs-identifier hs-var">body</span></a></span><span>              </span><span class="annot"><span class="annottext">ExprSize -&gt; Int -&gt; ExprSize
</span><a href="#local-6989586621680863749"><span class="hs-operator hs-var">`addSizeN`</span></a></span><span>
</span><span id="line-640"></span><span>        </span><span class="annot"><span class="annottext">Id -&gt; Int
forall {p}. Num p =&gt; Id -&gt; p
</span><a href="#local-6989586621680863742"><span class="hs-identifier hs-var">size_up_alloc</span></a></span><span> </span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680863746"><span class="hs-identifier hs-var">binder</span></a></span><span>
</span><span id="line-641"></span><span>
</span><span id="line-642"></span><span>    </span><span class="annot"><a href="#local-6989586621680863784"><span class="hs-identifier hs-var">size_up</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#Let"><span class="hs-identifier hs-type">Let</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#Rec"><span class="hs-identifier hs-type">Rec</span></a></span><span> </span><span id="local-6989586621680863740"><span class="annot"><span class="annottext">[(Id, CoreArg)]
</span><a href="#local-6989586621680863740"><span class="hs-identifier hs-var">pairs</span></a></span></span><span class="hs-special">)</span><span> </span><span id="local-6989586621680863739"><span class="annot"><span class="annottext">CoreArg
</span><a href="#local-6989586621680863739"><span class="hs-identifier hs-var">body</span></a></span></span><span class="hs-special">)</span><span>
</span><span id="line-643"></span><span>      </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">((Id, CoreArg) -&gt; ExprSize -&gt; ExprSize)
-&gt; ExprSize -&gt; [(Id, CoreArg)] -&gt; ExprSize
forall (t :: * -&gt; *) a b.
Foldable t =&gt;
(a -&gt; b -&gt; b) -&gt; b -&gt; t a -&gt; b
</span><a href="../../base/src/Data.Foldable.html#foldr"><span class="hs-identifier hs-var">foldr</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">ExprSize -&gt; ExprSize -&gt; ExprSize
</span><a href="#local-6989586621680863755"><span class="hs-identifier hs-var">addSizeNSD</span></a></span><span> </span><span class="annot"><span class="annottext">(ExprSize -&gt; ExprSize -&gt; ExprSize)
-&gt; ((Id, CoreArg) -&gt; ExprSize)
-&gt; (Id, CoreArg)
-&gt; ExprSize
-&gt; ExprSize
forall b c a. (b -&gt; c) -&gt; (a -&gt; b) -&gt; a -&gt; c
</span><a href="../../base/src/GHC.Base.html#."><span class="hs-operator hs-var">.</span></a></span><span> </span><span class="annot"><span class="annottext">(Id, CoreArg) -&gt; ExprSize
</span><a href="#local-6989586621680863743"><span class="hs-identifier hs-var">size_up_rhs</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-644"></span><span>              </span><span class="hs-special">(</span><span class="annot"><span class="annottext">CoreArg -&gt; ExprSize
</span><a href="#local-6989586621680863784"><span class="hs-identifier hs-var">size_up</span></a></span><span> </span><span class="annot"><span class="annottext">CoreArg
</span><a href="#local-6989586621680863739"><span class="hs-identifier hs-var">body</span></a></span><span> </span><span class="annot"><span class="annottext">ExprSize -&gt; Int -&gt; ExprSize
</span><a href="#local-6989586621680863749"><span class="hs-operator hs-var">`addSizeN`</span></a></span><span> </span><span class="annot"><span class="annottext">[Int] -&gt; Int
forall (t :: * -&gt; *) a. (Foldable t, Num a) =&gt; t a -&gt; a
</span><a href="../../base/src/Data.Foldable.html#sum"><span class="hs-identifier hs-var">sum</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">((Id, CoreArg) -&gt; Int) -&gt; [(Id, CoreArg)] -&gt; [Int]
forall a b. (a -&gt; b) -&gt; [a] -&gt; [b]
</span><a href="../../base/src/GHC.Base.html#map"><span class="hs-identifier hs-var">map</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Id -&gt; Int
forall {p}. Num p =&gt; Id -&gt; p
</span><a href="#local-6989586621680863742"><span class="hs-identifier hs-var">size_up_alloc</span></a></span><span> </span><span class="annot"><span class="annottext">(Id -&gt; Int) -&gt; ((Id, CoreArg) -&gt; Id) -&gt; (Id, CoreArg) -&gt; Int
forall b c a. (b -&gt; c) -&gt; (a -&gt; b) -&gt; a -&gt; c
</span><a href="../../base/src/GHC.Base.html#."><span class="hs-operator hs-var">.</span></a></span><span> </span><span class="annot"><span class="annottext">(Id, CoreArg) -&gt; Id
forall a b. (a, b) -&gt; a
</span><a href="../../base/src/Data.Tuple.html#fst"><span class="hs-identifier hs-var">fst</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">[(Id, CoreArg)]
</span><a href="#local-6989586621680863740"><span class="hs-identifier hs-var">pairs</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-645"></span><span>              </span><span class="annot"><span class="annottext">[(Id, CoreArg)]
</span><a href="#local-6989586621680863740"><span class="hs-identifier hs-var">pairs</span></a></span><span>
</span><span id="line-646"></span><span>
</span><span id="line-647"></span><span>    </span><span class="annot"><a href="#local-6989586621680863784"><span class="hs-identifier hs-var">size_up</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#Case"><span class="hs-identifier hs-type">Case</span></a></span><span> </span><span id="local-6989586621680863735"><span class="annot"><span class="annottext">CoreArg
</span><a href="#local-6989586621680863735"><span class="hs-identifier hs-var">e</span></a></span></span><span> </span><span class="annot"><span class="annottext">Id
</span><span class="hs-identifier">_</span></span><span> </span><span class="annot"><span class="annottext">Type
</span><span class="hs-identifier">_</span></span><span> </span><span id="local-6989586621680863734"><span class="annot"><span class="annottext">[Alt Id]
</span><a href="#local-6989586621680863734"><span class="hs-identifier hs-var">alts</span></a></span></span><span class="hs-special">)</span><span>
</span><span id="line-648"></span><span>        </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">[Alt Id] -&gt; Bool
forall (t :: * -&gt; *) a. Foldable t =&gt; t a -&gt; Bool
</span><a href="../../base/src/Data.Foldable.html#null"><span class="hs-identifier hs-var">null</span></a></span><span> </span><span class="annot"><span class="annottext">[Alt Id]
</span><a href="#local-6989586621680863734"><span class="hs-identifier hs-var">alts</span></a></span><span>
</span><span id="line-649"></span><span>        </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">CoreArg -&gt; ExprSize
</span><a href="#local-6989586621680863784"><span class="hs-identifier hs-var">size_up</span></a></span><span> </span><span class="annot"><span class="annottext">CoreArg
</span><a href="#local-6989586621680863735"><span class="hs-identifier hs-var">e</span></a></span><span>    </span><span class="hs-comment">-- case e of {} never returns, so take size of scrutinee</span><span>
</span><span id="line-650"></span><span>
</span><span id="line-651"></span><span>    </span><span class="annot"><a href="#local-6989586621680863784"><span class="hs-identifier hs-var">size_up</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#Case"><span class="hs-identifier hs-type">Case</span></a></span><span> </span><span id="local-6989586621680863732"><span class="annot"><span class="annottext">CoreArg
</span><a href="#local-6989586621680863732"><span class="hs-identifier hs-var">e</span></a></span></span><span> </span><span class="annot"><span class="annottext">Id
</span><span class="hs-identifier">_</span></span><span> </span><span class="annot"><span class="annottext">Type
</span><span class="hs-identifier">_</span></span><span> </span><span id="local-6989586621680863731"><span class="annot"><span class="annottext">[Alt Id]
</span><a href="#local-6989586621680863731"><span class="hs-identifier hs-var">alts</span></a></span></span><span class="hs-special">)</span><span>
</span><span id="line-652"></span><span>        </span><span class="hs-comment">-- Now alts is non-empty</span><span>
</span><span id="line-653"></span><span>        </span><span class="hs-glyph">|</span><span> </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span id="local-6989586621680863730"><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680863730"><span class="hs-identifier hs-var">v</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">CoreArg -&gt; Maybe Id
forall {b}. Expr b -&gt; Maybe Id
</span><a href="#local-6989586621680863729"><span class="hs-identifier hs-var">is_top_arg</span></a></span><span> </span><span class="annot"><span class="annottext">CoreArg
</span><a href="#local-6989586621680863732"><span class="hs-identifier hs-var">e</span></a></span><span> </span><span class="hs-comment">-- We are scrutinising an argument variable</span><span>
</span><span id="line-654"></span><span>        </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">let</span><span>
</span><span id="line-655"></span><span>            </span><span id="local-6989586621680863728"><span class="annot"><span class="annottext">alt_sizes :: [ExprSize]
</span><a href="#local-6989586621680863728"><span class="hs-identifier hs-var hs-var">alt_sizes</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(Alt Id -&gt; ExprSize) -&gt; [Alt Id] -&gt; [ExprSize]
forall a b. (a -&gt; b) -&gt; [a] -&gt; [b]
</span><a href="../../base/src/GHC.Base.html#map"><span class="hs-identifier hs-var">map</span></a></span><span> </span><span class="annot"><span class="annottext">Alt Id -&gt; ExprSize
</span><a href="#local-6989586621680863727"><span class="hs-identifier hs-var">size_up_alt</span></a></span><span> </span><span class="annot"><span class="annottext">[Alt Id]
</span><a href="#local-6989586621680863731"><span class="hs-identifier hs-var">alts</span></a></span><span>
</span><span id="line-656"></span><span>
</span><span id="line-657"></span><span>                  </span><span class="hs-comment">-- alts_size tries to compute a good discount for</span><span>
</span><span id="line-658"></span><span>                  </span><span class="hs-comment">-- the case when we are scrutinising an argument variable</span><span>
</span><span id="line-659"></span><span>            </span><span id="local-6989586621680863723"><span class="annot"><span class="annottext">alts_size :: ExprSize -&gt; ExprSize -&gt; ExprSize
</span><a href="#local-6989586621680863723"><span class="hs-identifier hs-var hs-var">alts_size</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.Unfold.html#SizeIs"><span class="hs-identifier hs-type">SizeIs</span></a></span><span> </span><span id="local-6989586621680863722"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863722"><span class="hs-identifier hs-var">tot</span></a></span></span><span> </span><span id="local-6989586621680863721"><span class="annot"><span class="annottext">Bag (Id, Int)
</span><a href="#local-6989586621680863721"><span class="hs-identifier hs-var">tot_disc</span></a></span></span><span> </span><span id="local-6989586621680863720"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863720"><span class="hs-identifier hs-var">tot_scrut</span></a></span></span><span class="hs-special">)</span><span>
</span><span id="line-660"></span><span>                          </span><span class="hs-comment">-- Size of all alternatives</span><span>
</span><span id="line-661"></span><span>                      </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.Unfold.html#SizeIs"><span class="hs-identifier hs-type">SizeIs</span></a></span><span> </span><span id="local-6989586621680863719"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863719"><span class="hs-identifier hs-var">max</span></a></span></span><span> </span><span class="annot"><span class="annottext">Bag (Id, Int)
</span><span class="hs-identifier">_</span></span><span>        </span><span class="annot"><span class="annottext">Int
</span><span class="hs-identifier">_</span></span><span class="hs-special">)</span><span>
</span><span id="line-662"></span><span>                          </span><span class="hs-comment">-- Size of biggest alternative</span><span>
</span><span id="line-663"></span><span>                  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int -&gt; Bag (Id, Int) -&gt; Int -&gt; ExprSize
</span><a href="GHC.Core.Unfold.html#SizeIs"><span class="hs-identifier hs-var">SizeIs</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863722"><span class="hs-identifier hs-var">tot</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">(Id, Int) -&gt; Bag (Id, Int)
forall a. a -&gt; Bag a
</span><a href="GHC.Data.Bag.html#unitBag"><span class="hs-identifier hs-var">unitBag</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680863730"><span class="hs-identifier hs-var">v</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">20</span></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="../../base/src/GHC.Num.html#%2B"><span class="hs-operator hs-var">+</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863722"><span class="hs-identifier hs-var">tot</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="../../base/src/GHC.Num.html#-"><span class="hs-glyph hs-var">-</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863719"><span class="hs-identifier hs-var">max</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-664"></span><span>                      </span><span class="annot"><span class="annottext">Bag (Id, Int) -&gt; Bag (Id, Int) -&gt; Bag (Id, Int)
forall a. Bag a -&gt; Bag a -&gt; Bag a
</span><a href="GHC.Data.Bag.html#unionBags"><span class="hs-operator hs-var">`unionBags`</span></a></span><span> </span><span class="annot"><span class="annottext">Bag (Id, Int)
</span><a href="#local-6989586621680863721"><span class="hs-identifier hs-var">tot_disc</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863720"><span class="hs-identifier hs-var">tot_scrut</span></a></span><span>
</span><span id="line-665"></span><span>                          </span><span class="hs-comment">-- If the variable is known, we produce a</span><span>
</span><span id="line-666"></span><span>                          </span><span class="hs-comment">-- discount that will take us back to 'max',</span><span>
</span><span id="line-667"></span><span>                          </span><span class="hs-comment">-- the size of the largest alternative The</span><span>
</span><span id="line-668"></span><span>                          </span><span class="hs-comment">-- 1+ is a little discount for reduced</span><span>
</span><span id="line-669"></span><span>                          </span><span class="hs-comment">-- allocation in the caller</span><span>
</span><span id="line-670"></span><span>                          </span><span class="hs-comment">--</span><span>
</span><span id="line-671"></span><span>                          </span><span class="hs-comment">-- Notice though, that we return tot_disc,</span><span>
</span><span id="line-672"></span><span>                          </span><span class="hs-comment">-- the total discount from all branches.  I</span><span>
</span><span id="line-673"></span><span>                          </span><span class="hs-comment">-- think that's right.</span><span>
</span><span id="line-674"></span><span>
</span><span id="line-675"></span><span>            </span><span class="annot"><a href="#local-6989586621680863723"><span class="hs-identifier hs-var">alts_size</span></a></span><span> </span><span id="local-6989586621680863716"><span class="annot"><span class="annottext">ExprSize
</span><a href="#local-6989586621680863716"><span class="hs-identifier hs-var">tot_size</span></a></span></span><span> </span><span class="annot"><span class="annottext">ExprSize
</span><span class="hs-identifier">_</span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">ExprSize
</span><a href="#local-6989586621680863716"><span class="hs-identifier hs-var">tot_size</span></a></span><span>
</span><span id="line-676"></span><span>          </span><span class="hs-keyword">in</span><span>
</span><span id="line-677"></span><span>          </span><span class="annot"><span class="annottext">ExprSize -&gt; ExprSize -&gt; ExprSize
</span><a href="#local-6989586621680863723"><span class="hs-identifier hs-var">alts_size</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">(ExprSize -&gt; ExprSize -&gt; ExprSize) -&gt; [ExprSize] -&gt; ExprSize
forall (t :: * -&gt; *) a. Foldable t =&gt; (a -&gt; a -&gt; a) -&gt; t a -&gt; a
</span><a href="../../base/src/Data.Foldable.html#foldr1"><span class="hs-identifier hs-var">foldr1</span></a></span><span> </span><span class="annot"><span class="annottext">ExprSize -&gt; ExprSize -&gt; ExprSize
</span><a href="#local-6989586621680863714"><span class="hs-identifier hs-var">addAltSize</span></a></span><span> </span><span class="annot"><span class="annottext">[ExprSize]
</span><a href="#local-6989586621680863728"><span class="hs-identifier hs-var">alt_sizes</span></a></span><span class="hs-special">)</span><span>  </span><span class="hs-comment">-- alts is non-empty</span><span>
</span><span id="line-678"></span><span>                    </span><span class="hs-special">(</span><span class="annot"><span class="annottext">(ExprSize -&gt; ExprSize -&gt; ExprSize) -&gt; [ExprSize] -&gt; ExprSize
forall (t :: * -&gt; *) a. Foldable t =&gt; (a -&gt; a -&gt; a) -&gt; t a -&gt; a
</span><a href="../../base/src/Data.Foldable.html#foldr1"><span class="hs-identifier hs-var">foldr1</span></a></span><span> </span><span class="annot"><span class="annottext">ExprSize -&gt; ExprSize -&gt; ExprSize
</span><a href="GHC.Core.Unfold.html#maxSize"><span class="hs-identifier hs-var">maxSize</span></a></span><span>    </span><span class="annot"><span class="annottext">[ExprSize]
</span><a href="#local-6989586621680863728"><span class="hs-identifier hs-var">alt_sizes</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-679"></span><span>                </span><span class="hs-comment">-- Good to inline if an arg is scrutinised, because</span><span>
</span><span id="line-680"></span><span>                </span><span class="hs-comment">-- that may eliminate allocation in the caller</span><span>
</span><span id="line-681"></span><span>                </span><span class="hs-comment">-- And it eliminates the case itself</span><span>
</span><span id="line-682"></span><span>        </span><span class="hs-keyword">where</span><span>
</span><span id="line-683"></span><span>          </span><span id="local-6989586621680863729"><span class="annot"><span class="annottext">is_top_arg :: Expr b -&gt; Maybe Id
</span><a href="#local-6989586621680863729"><span class="hs-identifier hs-var hs-var">is_top_arg</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#Var"><span class="hs-identifier hs-type">Var</span></a></span><span> </span><span id="local-6989586621680863710"><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680863710"><span class="hs-identifier hs-var">v</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680863710"><span class="hs-identifier hs-var">v</span></a></span><span> </span><span class="annot"><span class="annottext">Id -&gt; [Id] -&gt; Bool
forall (t :: * -&gt; *) a. (Foldable t, Eq a) =&gt; a -&gt; t a -&gt; Bool
</span><a href="../../base/src/Data.Foldable.html#elem"><span class="hs-operator hs-var">`elem`</span></a></span><span> </span><span class="annot"><span class="annottext">[Id]
</span><a href="#local-6989586621680863786"><span class="hs-identifier hs-var">top_args</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Id -&gt; Maybe Id
forall a. a -&gt; Maybe a
</span><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-var">Just</span></a></span><span> </span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680863710"><span class="hs-identifier hs-var">v</span></a></span><span>
</span><span id="line-684"></span><span>          </span><span class="annot"><a href="#local-6989586621680863729"><span class="hs-identifier hs-var">is_top_arg</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#Cast"><span class="hs-identifier hs-type">Cast</span></a></span><span> </span><span id="local-6989586621680863708"><span class="annot"><span class="annottext">Expr b
</span><a href="#local-6989586621680863708"><span class="hs-identifier hs-var">e</span></a></span></span><span> </span><span class="annot"><span class="annottext">CoercionR
</span><span class="hs-identifier">_</span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Expr b -&gt; Maybe Id
</span><a href="#local-6989586621680863729"><span class="hs-identifier hs-var">is_top_arg</span></a></span><span> </span><span class="annot"><span class="annottext">Expr b
</span><a href="#local-6989586621680863708"><span class="hs-identifier hs-var">e</span></a></span><span>
</span><span id="line-685"></span><span>          </span><span class="annot"><a href="#local-6989586621680863729"><span class="hs-identifier hs-var">is_top_arg</span></a></span><span> </span><span class="annot"><span class="annottext">Expr b
</span><span class="hs-identifier">_</span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Maybe Id
forall a. Maybe a
</span><a href="../../base/src/GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span>
</span><span id="line-686"></span><span>
</span><span id="line-687"></span><span>
</span><span id="line-688"></span><span>    </span><span class="annot"><a href="#local-6989586621680863784"><span class="hs-identifier hs-var">size_up</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#Case"><span class="hs-identifier hs-type">Case</span></a></span><span> </span><span id="local-6989586621680863707"><span class="annot"><span class="annottext">CoreArg
</span><a href="#local-6989586621680863707"><span class="hs-identifier hs-var">e</span></a></span></span><span> </span><span class="annot"><span class="annottext">Id
</span><span class="hs-identifier">_</span></span><span> </span><span class="annot"><span class="annottext">Type
</span><span class="hs-identifier">_</span></span><span> </span><span id="local-6989586621680863706"><span class="annot"><span class="annottext">[Alt Id]
</span><a href="#local-6989586621680863706"><span class="hs-identifier hs-var">alts</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">CoreArg -&gt; ExprSize
</span><a href="#local-6989586621680863784"><span class="hs-identifier hs-var">size_up</span></a></span><span> </span><span class="annot"><span class="annottext">CoreArg
</span><a href="#local-6989586621680863707"><span class="hs-identifier hs-var">e</span></a></span><span>  </span><span class="annot"><span class="annottext">ExprSize -&gt; ExprSize -&gt; ExprSize
</span><a href="#local-6989586621680863755"><span class="hs-operator hs-var">`addSizeNSD`</span></a></span><span>
</span><span id="line-689"></span><span>                                </span><span class="annot"><span class="annottext">(Alt Id -&gt; ExprSize -&gt; ExprSize)
-&gt; ExprSize -&gt; [Alt Id] -&gt; ExprSize
forall (t :: * -&gt; *) a b.
Foldable t =&gt;
(a -&gt; b -&gt; b) -&gt; b -&gt; t a -&gt; b
</span><a href="../../base/src/Data.Foldable.html#foldr"><span class="hs-identifier hs-var">foldr</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">ExprSize -&gt; ExprSize -&gt; ExprSize
</span><a href="#local-6989586621680863714"><span class="hs-identifier hs-var">addAltSize</span></a></span><span> </span><span class="annot"><span class="annottext">(ExprSize -&gt; ExprSize -&gt; ExprSize)
-&gt; (Alt Id -&gt; ExprSize) -&gt; Alt Id -&gt; ExprSize -&gt; ExprSize
forall b c a. (b -&gt; c) -&gt; (a -&gt; b) -&gt; a -&gt; c
</span><a href="../../base/src/GHC.Base.html#."><span class="hs-operator hs-var">.</span></a></span><span> </span><span class="annot"><span class="annottext">Alt Id -&gt; ExprSize
</span><a href="#local-6989586621680863727"><span class="hs-identifier hs-var">size_up_alt</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">ExprSize
</span><a href="#local-6989586621680863705"><span class="hs-identifier hs-var">case_size</span></a></span><span> </span><span class="annot"><span class="annottext">[Alt Id]
</span><a href="#local-6989586621680863706"><span class="hs-identifier hs-var">alts</span></a></span><span>
</span><span id="line-690"></span><span>      </span><span class="hs-keyword">where</span><span>
</span><span id="line-691"></span><span>          </span><span id="local-6989586621680863705"><span class="annot"><span class="annottext">case_size :: ExprSize
</span><a href="#local-6989586621680863705"><span class="hs-identifier hs-var hs-var">case_size</span></a></span></span><span>
</span><span id="line-692"></span><span>           </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">CoreArg -&gt; Bool
forall b. Expr b -&gt; Bool
</span><a href="#local-6989586621680863702"><span class="hs-identifier hs-var">is_inline_scrut</span></a></span><span> </span><span class="annot"><span class="annottext">CoreArg
</span><a href="#local-6989586621680863707"><span class="hs-identifier hs-var">e</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">[Alt Id] -&gt; Int -&gt; Bool
forall a. [a] -&gt; Int -&gt; Bool
</span><a href="GHC.Utils.Misc.html#lengthAtMost"><span class="hs-identifier hs-var">lengthAtMost</span></a></span><span> </span><span class="annot"><span class="annottext">[Alt Id]
</span><a href="#local-6989586621680863706"><span class="hs-identifier hs-var">alts</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">1</span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int -&gt; ExprSize
</span><a href="GHC.Core.Unfold.html#sizeN"><span class="hs-identifier hs-var">sizeN</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-glyph">-</span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">10</span></span><span class="hs-special">)</span><span>
</span><span id="line-693"></span><span>           </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">ExprSize
</span><a href="GHC.Core.Unfold.html#sizeZero"><span class="hs-identifier hs-var">sizeZero</span></a></span><span>
</span><span id="line-694"></span><span>                </span><span class="hs-comment">-- Normally we don't charge for the case itself, but</span><span>
</span><span id="line-695"></span><span>                </span><span class="hs-comment">-- we charge one per alternative (see size_up_alt,</span><span>
</span><span id="line-696"></span><span>                </span><span class="hs-comment">-- below) to account for the cost of the info table</span><span>
</span><span id="line-697"></span><span>                </span><span class="hs-comment">-- and comparisons.</span><span>
</span><span id="line-698"></span><span>                </span><span class="hs-comment">--</span><span>
</span><span id="line-699"></span><span>                </span><span class="hs-comment">-- However, in certain cases (see is_inline_scrut</span><span>
</span><span id="line-700"></span><span>                </span><span class="hs-comment">-- below), no code is generated for the case unless</span><span>
</span><span id="line-701"></span><span>                </span><span class="hs-comment">-- there are multiple alts.  In these cases we</span><span>
</span><span id="line-702"></span><span>                </span><span class="hs-comment">-- subtract one, making the first alt free.</span><span>
</span><span id="line-703"></span><span>                </span><span class="hs-comment">-- e.g. case x# +# y# of _ -&gt; ...   should cost 1</span><span>
</span><span id="line-704"></span><span>                </span><span class="hs-comment">--      case touch# x# of _ -&gt; ...  should cost 0</span><span>
</span><span id="line-705"></span><span>                </span><span class="hs-comment">-- (see #4978)</span><span>
</span><span id="line-706"></span><span>                </span><span class="hs-comment">--</span><span>
</span><span id="line-707"></span><span>                </span><span class="hs-comment">-- I would like to not have the &quot;lengthAtMost alts 1&quot;</span><span>
</span><span id="line-708"></span><span>                </span><span class="hs-comment">-- condition above, but without that some programs got worse</span><span>
</span><span id="line-709"></span><span>                </span><span class="hs-comment">-- (spectral/hartel/event and spectral/para).  I don't fully</span><span>
</span><span id="line-710"></span><span>                </span><span class="hs-comment">-- understand why. (SDM 24/5/11)</span><span>
</span><span id="line-711"></span><span>
</span><span id="line-712"></span><span>                </span><span class="hs-comment">-- unboxed variables, inline primops and unsafe foreign calls</span><span>
</span><span id="line-713"></span><span>                </span><span class="hs-comment">-- are all &quot;inline&quot; things:</span><span>
</span><span id="line-714"></span><span>          </span><span id="local-6989586621680863702"><span class="annot"><span class="annottext">is_inline_scrut :: Expr b -&gt; Bool
</span><a href="#local-6989586621680863702"><span class="hs-identifier hs-var hs-var">is_inline_scrut</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#Var"><span class="hs-identifier hs-type">Var</span></a></span><span> </span><span id="local-6989586621680863699"><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680863699"><span class="hs-identifier hs-var">v</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">HasDebugCallStack =&gt; Type -&gt; Bool
Type -&gt; Bool
</span><a href="GHC.Core.Type.html#isUnliftedType"><span class="hs-identifier hs-var">isUnliftedType</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Id -&gt; Type
</span><a href="GHC.Types.Id.html#idType"><span class="hs-identifier hs-var">idType</span></a></span><span> </span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680863699"><span class="hs-identifier hs-var">v</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-715"></span><span>          </span><span class="annot"><a href="#local-6989586621680863702"><span class="hs-identifier hs-var">is_inline_scrut</span></a></span><span> </span><span id="local-6989586621680863697"><span class="annot"><span class="annottext">Expr b
</span><a href="#local-6989586621680863697"><span class="hs-identifier hs-var">scrut</span></a></span></span><span>
</span><span id="line-716"></span><span>              </span><span class="hs-glyph">|</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#Var"><span class="hs-identifier hs-type">Var</span></a></span><span> </span><span id="local-6989586621680863696"><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680863696"><span class="hs-identifier hs-var">f</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">[Expr b]
</span><span class="hs-identifier">_</span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Expr b -&gt; (Expr b, [Expr b])
forall b. Expr b -&gt; (Expr b, [Expr b])
</span><a href="GHC.Core.html#collectArgs"><span class="hs-identifier hs-var">collectArgs</span></a></span><span> </span><span class="annot"><span class="annottext">Expr b
</span><a href="#local-6989586621680863697"><span class="hs-identifier hs-var">scrut</span></a></span><span>
</span><span id="line-717"></span><span>                </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">Id -&gt; IdDetails
</span><a href="GHC.Types.Var.html#idDetails"><span class="hs-identifier hs-var">idDetails</span></a></span><span> </span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680863696"><span class="hs-identifier hs-var">f</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-718"></span><span>                    </span><span class="annot"><a href="GHC.Types.Id.Info.html#FCallId"><span class="hs-identifier hs-type">FCallId</span></a></span><span> </span><span id="local-6989586621680863692"><span class="annot"><span class="annottext">ForeignCall
</span><a href="#local-6989586621680863692"><span class="hs-identifier hs-var">fc</span></a></span></span><span>  </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Bool
</span><span class="hs-identifier hs-var">not</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">ForeignCall -&gt; Bool
</span><a href="GHC.Types.ForeignCall.html#isSafeForeignCall"><span class="hs-identifier hs-var">isSafeForeignCall</span></a></span><span> </span><span class="annot"><span class="annottext">ForeignCall
</span><a href="#local-6989586621680863692"><span class="hs-identifier hs-var">fc</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-719"></span><span>                    </span><span class="annot"><a href="GHC.Types.Id.Info.html#PrimOpId"><span class="hs-identifier hs-type">PrimOpId</span></a></span><span> </span><span id="local-6989586621680863689"><span class="annot"><span class="annottext">PrimOp
</span><a href="#local-6989586621680863689"><span class="hs-identifier hs-var">op</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Bool
</span><span class="hs-identifier hs-var">not</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">PrimOp -&gt; Bool
</span><a href="GHC.Builtin.PrimOps.html#primOpOutOfLine"><span class="hs-identifier hs-var">primOpOutOfLine</span></a></span><span> </span><span class="annot"><span class="annottext">PrimOp
</span><a href="#local-6989586621680863689"><span class="hs-identifier hs-var">op</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-720"></span><span>                    </span><span id="local-6989586621680863687"><span class="annot"><span class="annottext">IdDetails
</span><a href="#local-6989586621680863687"><span class="hs-identifier hs-var">_other</span></a></span></span><span>      </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">False</span></span><span>
</span><span id="line-721"></span><span>              </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span>
</span><span id="line-722"></span><span>                </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">False</span></span><span>
</span><span id="line-723"></span><span>
</span><span id="line-724"></span><span>    </span><span id="local-6989586621680863743"><span class="annot"><span class="annottext">size_up_rhs :: (Id, CoreArg) -&gt; ExprSize
</span><a href="#local-6989586621680863743"><span class="hs-identifier hs-var hs-var">size_up_rhs</span></a></span></span><span> </span><span class="hs-special">(</span><span id="local-6989586621680863686"><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680863686"><span class="hs-identifier hs-var">bndr</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621680863685"><span class="annot"><span class="annottext">CoreArg
</span><a href="#local-6989586621680863685"><span class="hs-identifier hs-var">rhs</span></a></span></span><span class="hs-special">)</span><span>
</span><span id="line-725"></span><span>      </span><span class="hs-glyph">|</span><span> </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span id="local-6989586621680863684"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863684"><span class="hs-identifier hs-var">join_arity</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Id -&gt; Maybe Int
</span><a href="GHC.Types.Id.html#isJoinId_maybe"><span class="hs-identifier hs-var">isJoinId_maybe</span></a></span><span> </span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680863686"><span class="hs-identifier hs-var">bndr</span></a></span><span>
</span><span id="line-726"></span><span>        </span><span class="hs-comment">-- Skip arguments to join point</span><span>
</span><span id="line-727"></span><span>      </span><span class="hs-special">,</span><span> </span><span class="hs-special">(</span><span id="local-6989586621680863682"><span class="annot"><span class="annottext">[Id]
</span><a href="#local-6989586621680863682"><span class="hs-identifier hs-var">_bndrs</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621680863681"><span class="annot"><span class="annottext">CoreArg
</span><a href="#local-6989586621680863681"><span class="hs-identifier hs-var">body</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Int -&gt; CoreArg -&gt; ([Id], CoreArg)
forall b. Int -&gt; Expr b -&gt; ([b], Expr b)
</span><a href="GHC.Core.html#collectNBinders"><span class="hs-identifier hs-var">collectNBinders</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863684"><span class="hs-identifier hs-var">join_arity</span></a></span><span> </span><span class="annot"><span class="annottext">CoreArg
</span><a href="#local-6989586621680863685"><span class="hs-identifier hs-var">rhs</span></a></span><span>
</span><span id="line-728"></span><span>      </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">CoreArg -&gt; ExprSize
</span><a href="#local-6989586621680863784"><span class="hs-identifier hs-var">size_up</span></a></span><span> </span><span class="annot"><span class="annottext">CoreArg
</span><a href="#local-6989586621680863681"><span class="hs-identifier hs-var">body</span></a></span><span>
</span><span id="line-729"></span><span>      </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span>
</span><span id="line-730"></span><span>      </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">CoreArg -&gt; ExprSize
</span><a href="#local-6989586621680863784"><span class="hs-identifier hs-var">size_up</span></a></span><span> </span><span class="annot"><span class="annottext">CoreArg
</span><a href="#local-6989586621680863685"><span class="hs-identifier hs-var">rhs</span></a></span><span>
</span><span id="line-731"></span><span>
</span><span id="line-732"></span><span>    </span><span class="hs-comment">------------</span><span>
</span><span id="line-733"></span><span>    </span><span class="hs-comment">-- size_up_app is used when there's ONE OR MORE value args</span><span>
</span><span id="line-734"></span><span>    </span><span id="local-6989586621680863754"><span class="annot"><span class="annottext">size_up_app :: CoreArg -&gt; [CoreArg] -&gt; Int -&gt; ExprSize
</span><a href="#local-6989586621680863754"><span class="hs-identifier hs-var hs-var">size_up_app</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#App"><span class="hs-identifier hs-type">App</span></a></span><span> </span><span id="local-6989586621680863679"><span class="annot"><span class="annottext">CoreArg
</span><a href="#local-6989586621680863679"><span class="hs-identifier hs-var">fun</span></a></span></span><span> </span><span id="local-6989586621680863678"><span class="annot"><span class="annottext">CoreArg
</span><a href="#local-6989586621680863678"><span class="hs-identifier hs-var">arg</span></a></span></span><span class="hs-special">)</span><span> </span><span id="local-6989586621680863677"><span class="annot"><span class="annottext">[CoreArg]
</span><a href="#local-6989586621680863677"><span class="hs-identifier hs-var">args</span></a></span></span><span> </span><span id="local-6989586621680863676"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863676"><span class="hs-identifier hs-var">voids</span></a></span></span><span>
</span><span id="line-735"></span><span>        </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">CoreArg -&gt; Bool
forall b. Expr b -&gt; Bool
</span><a href="GHC.Core.html#isTyCoArg"><span class="hs-identifier hs-var">isTyCoArg</span></a></span><span> </span><span class="annot"><span class="annottext">CoreArg
</span><a href="#local-6989586621680863678"><span class="hs-identifier hs-var">arg</span></a></span><span>                  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">CoreArg -&gt; [CoreArg] -&gt; Int -&gt; ExprSize
</span><a href="#local-6989586621680863754"><span class="hs-identifier hs-var">size_up_app</span></a></span><span> </span><span class="annot"><span class="annottext">CoreArg
</span><a href="#local-6989586621680863679"><span class="hs-identifier hs-var">fun</span></a></span><span> </span><span class="annot"><span class="annottext">[CoreArg]
</span><a href="#local-6989586621680863677"><span class="hs-identifier hs-var">args</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863676"><span class="hs-identifier hs-var">voids</span></a></span><span>
</span><span id="line-736"></span><span>        </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">CoreArg -&gt; Bool
forall b. Expr b -&gt; Bool
</span><a href="#local-6989586621680863753"><span class="hs-identifier hs-var">isRealWorldExpr</span></a></span><span> </span><span class="annot"><span class="annottext">CoreArg
</span><a href="#local-6989586621680863678"><span class="hs-identifier hs-var">arg</span></a></span><span>            </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">CoreArg -&gt; [CoreArg] -&gt; Int -&gt; ExprSize
</span><a href="#local-6989586621680863754"><span class="hs-identifier hs-var">size_up_app</span></a></span><span> </span><span class="annot"><span class="annottext">CoreArg
</span><a href="#local-6989586621680863679"><span class="hs-identifier hs-var">fun</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">CoreArg
</span><a href="#local-6989586621680863678"><span class="hs-identifier hs-var">arg</span></a></span><span class="annot"><span class="annottext">CoreArg -&gt; [CoreArg] -&gt; [CoreArg]
forall a. a -&gt; [a] -&gt; [a]
</span><span class="hs-glyph hs-var">:</span></span><span class="annot"><span class="annottext">[CoreArg]
</span><a href="#local-6989586621680863677"><span class="hs-identifier hs-var">args</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863676"><span class="hs-identifier hs-var">voids</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="../../base/src/GHC.Num.html#%2B"><span class="hs-operator hs-var">+</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">1</span></span><span class="hs-special">)</span><span>
</span><span id="line-737"></span><span>        </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span>                      </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">CoreArg -&gt; ExprSize
</span><a href="#local-6989586621680863784"><span class="hs-identifier hs-var">size_up</span></a></span><span> </span><span class="annot"><span class="annottext">CoreArg
</span><a href="#local-6989586621680863678"><span class="hs-identifier hs-var">arg</span></a></span><span>  </span><span class="annot"><span class="annottext">ExprSize -&gt; ExprSize -&gt; ExprSize
</span><a href="#local-6989586621680863755"><span class="hs-operator hs-var">`addSizeNSD`</span></a></span><span>
</span><span id="line-738"></span><span>                                           </span><span class="annot"><span class="annottext">CoreArg -&gt; [CoreArg] -&gt; Int -&gt; ExprSize
</span><a href="#local-6989586621680863754"><span class="hs-identifier hs-var">size_up_app</span></a></span><span> </span><span class="annot"><span class="annottext">CoreArg
</span><a href="#local-6989586621680863679"><span class="hs-identifier hs-var">fun</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">CoreArg
</span><a href="#local-6989586621680863678"><span class="hs-identifier hs-var">arg</span></a></span><span class="annot"><span class="annottext">CoreArg -&gt; [CoreArg] -&gt; [CoreArg]
forall a. a -&gt; [a] -&gt; [a]
</span><span class="hs-glyph hs-var">:</span></span><span class="annot"><span class="annottext">[CoreArg]
</span><a href="#local-6989586621680863677"><span class="hs-identifier hs-var">args</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863676"><span class="hs-identifier hs-var">voids</span></a></span><span>
</span><span id="line-739"></span><span>    </span><span class="annot"><a href="#local-6989586621680863754"><span class="hs-identifier hs-var">size_up_app</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#Var"><span class="hs-identifier hs-type">Var</span></a></span><span> </span><span id="local-6989586621680863675"><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680863675"><span class="hs-identifier hs-var">fun</span></a></span></span><span class="hs-special">)</span><span>     </span><span id="local-6989586621680863674"><span class="annot"><span class="annottext">[CoreArg]
</span><a href="#local-6989586621680863674"><span class="hs-identifier hs-var">args</span></a></span></span><span> </span><span id="local-6989586621680863673"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863673"><span class="hs-identifier hs-var">voids</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Id -&gt; [CoreArg] -&gt; Int -&gt; ExprSize
</span><a href="#local-6989586621680863759"><span class="hs-identifier hs-var">size_up_call</span></a></span><span> </span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680863675"><span class="hs-identifier hs-var">fun</span></a></span><span> </span><span class="annot"><span class="annottext">[CoreArg]
</span><a href="#local-6989586621680863674"><span class="hs-identifier hs-var">args</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863673"><span class="hs-identifier hs-var">voids</span></a></span><span>
</span><span id="line-740"></span><span>    </span><span class="annot"><a href="#local-6989586621680863754"><span class="hs-identifier hs-var">size_up_app</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#Tick"><span class="hs-identifier hs-type">Tick</span></a></span><span> </span><span class="annot"><span class="annottext">Tickish Id
</span><span class="hs-identifier">_</span></span><span> </span><span id="local-6989586621680863672"><span class="annot"><span class="annottext">CoreArg
</span><a href="#local-6989586621680863672"><span class="hs-identifier hs-var">expr</span></a></span></span><span class="hs-special">)</span><span> </span><span id="local-6989586621680863671"><span class="annot"><span class="annottext">[CoreArg]
</span><a href="#local-6989586621680863671"><span class="hs-identifier hs-var">args</span></a></span></span><span> </span><span id="local-6989586621680863670"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863670"><span class="hs-identifier hs-var">voids</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">CoreArg -&gt; [CoreArg] -&gt; Int -&gt; ExprSize
</span><a href="#local-6989586621680863754"><span class="hs-identifier hs-var">size_up_app</span></a></span><span> </span><span class="annot"><span class="annottext">CoreArg
</span><a href="#local-6989586621680863672"><span class="hs-identifier hs-var">expr</span></a></span><span> </span><span class="annot"><span class="annottext">[CoreArg]
</span><a href="#local-6989586621680863671"><span class="hs-identifier hs-var">args</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863670"><span class="hs-identifier hs-var">voids</span></a></span><span>
</span><span id="line-741"></span><span>    </span><span class="annot"><a href="#local-6989586621680863754"><span class="hs-identifier hs-var">size_up_app</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#Cast"><span class="hs-identifier hs-type">Cast</span></a></span><span> </span><span id="local-6989586621680863669"><span class="annot"><span class="annottext">CoreArg
</span><a href="#local-6989586621680863669"><span class="hs-identifier hs-var">expr</span></a></span></span><span> </span><span class="annot"><span class="annottext">CoercionR
</span><span class="hs-identifier">_</span></span><span class="hs-special">)</span><span> </span><span id="local-6989586621680863668"><span class="annot"><span class="annottext">[CoreArg]
</span><a href="#local-6989586621680863668"><span class="hs-identifier hs-var">args</span></a></span></span><span> </span><span id="local-6989586621680863667"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863667"><span class="hs-identifier hs-var">voids</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">CoreArg -&gt; [CoreArg] -&gt; Int -&gt; ExprSize
</span><a href="#local-6989586621680863754"><span class="hs-identifier hs-var">size_up_app</span></a></span><span> </span><span class="annot"><span class="annottext">CoreArg
</span><a href="#local-6989586621680863669"><span class="hs-identifier hs-var">expr</span></a></span><span> </span><span class="annot"><span class="annottext">[CoreArg]
</span><a href="#local-6989586621680863668"><span class="hs-identifier hs-var">args</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863667"><span class="hs-identifier hs-var">voids</span></a></span><span>
</span><span id="line-742"></span><span>    </span><span class="annot"><a href="#local-6989586621680863754"><span class="hs-identifier hs-var">size_up_app</span></a></span><span> </span><span id="local-6989586621680863666"><span class="annot"><span class="annottext">CoreArg
</span><a href="#local-6989586621680863666"><span class="hs-identifier hs-var">other</span></a></span></span><span>         </span><span id="local-6989586621680863665"><span class="annot"><span class="annottext">[CoreArg]
</span><a href="#local-6989586621680863665"><span class="hs-identifier hs-var">args</span></a></span></span><span> </span><span id="local-6989586621680863664"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863664"><span class="hs-identifier hs-var">voids</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">CoreArg -&gt; ExprSize
</span><a href="#local-6989586621680863784"><span class="hs-identifier hs-var">size_up</span></a></span><span> </span><span class="annot"><span class="annottext">CoreArg
</span><a href="#local-6989586621680863666"><span class="hs-identifier hs-var">other</span></a></span><span> </span><span class="annot"><span class="annottext">ExprSize -&gt; Int -&gt; ExprSize
</span><a href="#local-6989586621680863749"><span class="hs-operator hs-var">`addSizeN`</span></a></span><span>
</span><span id="line-743"></span><span>                                           </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
</span><a href="GHC.Core.Unfold.html#callSize"><span class="hs-identifier hs-var">callSize</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">[CoreArg] -&gt; Int
forall (t :: * -&gt; *) a. Foldable t =&gt; t a -&gt; Int
</span><a href="../../base/src/Data.Foldable.html#length"><span class="hs-identifier hs-var">length</span></a></span><span> </span><span class="annot"><span class="annottext">[CoreArg]
</span><a href="#local-6989586621680863665"><span class="hs-identifier hs-var">args</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863664"><span class="hs-identifier hs-var">voids</span></a></span><span>
</span><span id="line-744"></span><span>       </span><span class="hs-comment">-- if the lhs is not an App or a Var, or an invisible thing like a</span><span>
</span><span id="line-745"></span><span>       </span><span class="hs-comment">-- Tick or Cast, then we should charge for a complete call plus the</span><span>
</span><span id="line-746"></span><span>       </span><span class="hs-comment">-- size of the lhs itself.</span><span>
</span><span id="line-747"></span><span>
</span><span id="line-748"></span><span>    </span><span class="hs-comment">------------</span><span>
</span><span id="line-749"></span><span>    </span><span class="annot"><a href="#local-6989586621680863759"><span class="hs-identifier hs-type">size_up_call</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Types.Var.html#Id"><span class="hs-identifier hs-type">Id</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.html#CoreExpr"><span class="hs-identifier hs-type">CoreExpr</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Int</span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.Unfold.html#ExprSize"><span class="hs-identifier hs-type">ExprSize</span></a></span><span>
</span><span id="line-750"></span><span>    </span><span id="local-6989586621680863759"><span class="annot"><span class="annottext">size_up_call :: Id -&gt; [CoreArg] -&gt; Int -&gt; ExprSize
</span><a href="#local-6989586621680863759"><span class="hs-identifier hs-var hs-var">size_up_call</span></a></span></span><span> </span><span id="local-6989586621680863662"><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680863662"><span class="hs-identifier hs-var">fun</span></a></span></span><span> </span><span id="local-6989586621680863661"><span class="annot"><span class="annottext">[CoreArg]
</span><a href="#local-6989586621680863661"><span class="hs-identifier hs-var">val_args</span></a></span></span><span> </span><span id="local-6989586621680863660"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863660"><span class="hs-identifier hs-var">voids</span></a></span></span><span>
</span><span id="line-751"></span><span>       </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">Id -&gt; IdDetails
</span><a href="GHC.Types.Var.html#idDetails"><span class="hs-identifier hs-var">idDetails</span></a></span><span> </span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680863662"><span class="hs-identifier hs-var">fun</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-752"></span><span>           </span><span class="annot"><a href="GHC.Types.Id.Info.html#FCallId"><span class="hs-identifier hs-type">FCallId</span></a></span><span> </span><span class="annot"><span class="annottext">ForeignCall
</span><span class="hs-identifier">_</span></span><span>        </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Int -&gt; ExprSize
</span><a href="GHC.Core.Unfold.html#sizeN"><span class="hs-identifier hs-var">sizeN</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
</span><a href="GHC.Core.Unfold.html#callSize"><span class="hs-identifier hs-var">callSize</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">[CoreArg] -&gt; Int
forall (t :: * -&gt; *) a. Foldable t =&gt; t a -&gt; Int
</span><a href="../../base/src/Data.Foldable.html#length"><span class="hs-identifier hs-var">length</span></a></span><span> </span><span class="annot"><span class="annottext">[CoreArg]
</span><a href="#local-6989586621680863661"><span class="hs-identifier hs-var">val_args</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863660"><span class="hs-identifier hs-var">voids</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-753"></span><span>           </span><span class="annot"><a href="GHC.Types.Id.Info.html#DataConWorkId"><span class="hs-identifier hs-type">DataConWorkId</span></a></span><span> </span><span id="local-6989586621680863658"><span class="annot"><span class="annottext">DataCon
</span><a href="#local-6989586621680863658"><span class="hs-identifier hs-var">dc</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">DataCon -&gt; Int -&gt; ExprSize
</span><a href="GHC.Core.Unfold.html#conSize"><span class="hs-identifier hs-var">conSize</span></a></span><span>    </span><span class="annot"><span class="annottext">DataCon
</span><a href="#local-6989586621680863658"><span class="hs-identifier hs-var">dc</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">[CoreArg] -&gt; Int
forall (t :: * -&gt; *) a. Foldable t =&gt; t a -&gt; Int
</span><a href="../../base/src/Data.Foldable.html#length"><span class="hs-identifier hs-var">length</span></a></span><span> </span><span class="annot"><span class="annottext">[CoreArg]
</span><a href="#local-6989586621680863661"><span class="hs-identifier hs-var">val_args</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-754"></span><span>           </span><span class="annot"><a href="GHC.Types.Id.Info.html#PrimOpId"><span class="hs-identifier hs-type">PrimOpId</span></a></span><span> </span><span id="local-6989586621680863656"><span class="annot"><span class="annottext">PrimOp
</span><a href="#local-6989586621680863656"><span class="hs-identifier hs-var">op</span></a></span></span><span>      </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">PrimOp -&gt; Int -&gt; ExprSize
</span><a href="GHC.Core.Unfold.html#primOpSize"><span class="hs-identifier hs-var">primOpSize</span></a></span><span> </span><span class="annot"><span class="annottext">PrimOp
</span><a href="#local-6989586621680863656"><span class="hs-identifier hs-var">op</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">[CoreArg] -&gt; Int
forall (t :: * -&gt; *) a. Foldable t =&gt; t a -&gt; Int
</span><a href="../../base/src/Data.Foldable.html#length"><span class="hs-identifier hs-var">length</span></a></span><span> </span><span class="annot"><span class="annottext">[CoreArg]
</span><a href="#local-6989586621680863661"><span class="hs-identifier hs-var">val_args</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-755"></span><span>           </span><span class="annot"><a href="GHC.Types.Id.Info.html#ClassOpId"><span class="hs-identifier hs-type">ClassOpId</span></a></span><span> </span><span class="annot"><span class="annottext">Class
</span><span class="hs-identifier">_</span></span><span>      </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">DynFlags -&gt; [Id] -&gt; [CoreArg] -&gt; ExprSize
</span><a href="GHC.Core.Unfold.html#classOpSize"><span class="hs-identifier hs-var">classOpSize</span></a></span><span> </span><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680863788"><span class="hs-identifier hs-var">dflags</span></a></span><span> </span><span class="annot"><span class="annottext">[Id]
</span><a href="#local-6989586621680863786"><span class="hs-identifier hs-var">top_args</span></a></span><span> </span><span class="annot"><span class="annottext">[CoreArg]
</span><a href="#local-6989586621680863661"><span class="hs-identifier hs-var">val_args</span></a></span><span>
</span><span id="line-756"></span><span>           </span><span class="annot"><span class="annottext">IdDetails
</span><span class="hs-identifier">_</span></span><span>                </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">DynFlags -&gt; [Id] -&gt; Id -&gt; Int -&gt; Int -&gt; ExprSize
</span><a href="GHC.Core.Unfold.html#funSize"><span class="hs-identifier hs-var">funSize</span></a></span><span> </span><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680863788"><span class="hs-identifier hs-var">dflags</span></a></span><span> </span><span class="annot"><span class="annottext">[Id]
</span><a href="#local-6989586621680863786"><span class="hs-identifier hs-var">top_args</span></a></span><span> </span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680863662"><span class="hs-identifier hs-var">fun</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">[CoreArg] -&gt; Int
forall (t :: * -&gt; *) a. Foldable t =&gt; t a -&gt; Int
</span><a href="../../base/src/Data.Foldable.html#length"><span class="hs-identifier hs-var">length</span></a></span><span> </span><span class="annot"><span class="annottext">[CoreArg]
</span><a href="#local-6989586621680863661"><span class="hs-identifier hs-var">val_args</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863660"><span class="hs-identifier hs-var">voids</span></a></span><span>
</span><span id="line-757"></span><span>
</span><span id="line-758"></span><span>    </span><span class="hs-comment">------------</span><span>
</span><span id="line-759"></span><span>    </span><span id="local-6989586621680863727"><span class="annot"><span class="annottext">size_up_alt :: Alt Id -&gt; ExprSize
</span><a href="#local-6989586621680863727"><span class="hs-identifier hs-var hs-var">size_up_alt</span></a></span></span><span> </span><span class="hs-special">(</span><span id="local-6989586621680863651"><span class="annot"><span class="annottext">AltCon
</span><a href="#local-6989586621680863651"><span class="hs-identifier hs-var">_con</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621680863650"><span class="annot"><span class="annottext">[Id]
</span><a href="#local-6989586621680863650"><span class="hs-identifier hs-var">_bndrs</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621680863649"><span class="annot"><span class="annottext">CoreArg
</span><a href="#local-6989586621680863649"><span class="hs-identifier hs-var">rhs</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">CoreArg -&gt; ExprSize
</span><a href="#local-6989586621680863784"><span class="hs-identifier hs-var">size_up</span></a></span><span> </span><span class="annot"><span class="annottext">CoreArg
</span><a href="#local-6989586621680863649"><span class="hs-identifier hs-var">rhs</span></a></span><span> </span><span class="annot"><span class="annottext">ExprSize -&gt; Int -&gt; ExprSize
</span><a href="#local-6989586621680863749"><span class="hs-operator hs-var">`addSizeN`</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">10</span></span><span>
</span><span id="line-760"></span><span>        </span><span class="hs-comment">-- Don't charge for args, so that wrappers look cheap</span><span>
</span><span id="line-761"></span><span>        </span><span class="hs-comment">-- (See comments about wrappers with Case)</span><span>
</span><span id="line-762"></span><span>        </span><span class="hs-comment">--</span><span>
</span><span id="line-763"></span><span>        </span><span class="hs-comment">-- IMPORTANT: *do* charge 1 for the alternative, else we</span><span>
</span><span id="line-764"></span><span>        </span><span class="hs-comment">-- find that giant case nests are treated as practically free</span><span>
</span><span id="line-765"></span><span>        </span><span class="hs-comment">-- A good example is Foreign.C.Error.errnoToIOError</span><span>
</span><span id="line-766"></span><span>
</span><span id="line-767"></span><span>    </span><span class="hs-comment">------------</span><span>
</span><span id="line-768"></span><span>    </span><span class="hs-comment">-- Cost to allocate binding with given binder</span><span>
</span><span id="line-769"></span><span>    </span><span id="local-6989586621680863742"><span class="annot"><span class="annottext">size_up_alloc :: Id -&gt; p
</span><a href="#local-6989586621680863742"><span class="hs-identifier hs-var hs-var">size_up_alloc</span></a></span></span><span> </span><span id="local-6989586621680863644"><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680863644"><span class="hs-identifier hs-var">bndr</span></a></span></span><span>
</span><span id="line-770"></span><span>      </span><span class="hs-glyph">|</span><span>  </span><span class="annot"><span class="annottext">Id -&gt; Bool
</span><a href="GHC.Types.Var.html#isTyVar"><span class="hs-identifier hs-var">isTyVar</span></a></span><span> </span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680863644"><span class="hs-identifier hs-var">bndr</span></a></span><span>                 </span><span class="hs-comment">-- Doesn't exist at runtime</span><span>
</span><span id="line-771"></span><span>      </span><span class="annot"><span class="annottext">Bool -&gt; Bool -&gt; Bool
</span><span class="hs-operator hs-var">||</span></span><span> </span><span class="annot"><span class="annottext">Id -&gt; Bool
</span><a href="GHC.Types.Id.html#isJoinId"><span class="hs-identifier hs-var">isJoinId</span></a></span><span> </span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680863644"><span class="hs-identifier hs-var">bndr</span></a></span><span>                </span><span class="hs-comment">-- Not allocated at all</span><span>
</span><span id="line-772"></span><span>      </span><span class="annot"><span class="annottext">Bool -&gt; Bool -&gt; Bool
</span><span class="hs-operator hs-var">||</span></span><span> </span><span class="annot"><span class="annottext">HasDebugCallStack =&gt; Type -&gt; Bool
Type -&gt; Bool
</span><a href="GHC.Core.Type.html#isUnliftedType"><span class="hs-identifier hs-var">isUnliftedType</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Id -&gt; Type
</span><a href="GHC.Types.Id.html#idType"><span class="hs-identifier hs-var">idType</span></a></span><span> </span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680863644"><span class="hs-identifier hs-var">bndr</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-comment">-- Doesn't live in heap</span><span>
</span><span id="line-773"></span><span>      </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">p
</span><span class="hs-number">0</span></span><span>
</span><span id="line-774"></span><span>      </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span>
</span><span id="line-775"></span><span>      </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">p
</span><span class="hs-number">10</span></span><span>
</span><span id="line-776"></span><span>
</span><span id="line-777"></span><span>    </span><span class="hs-comment">------------</span><span>
</span><span id="line-778"></span><span>        </span><span class="hs-comment">-- These addSize things have to be here because</span><span>
</span><span id="line-779"></span><span>        </span><span class="hs-comment">-- I don't want to give them bOMB_OUT_SIZE as an argument</span><span>
</span><span id="line-780"></span><span>    </span><span id="local-6989586621680863749"><span class="annot"><span class="annottext">addSizeN :: ExprSize -&gt; Int -&gt; ExprSize
</span><a href="#local-6989586621680863749"><span class="hs-identifier hs-var hs-var">addSizeN</span></a></span></span><span> </span><span class="annot"><span class="annottext">ExprSize
</span><a href="GHC.Core.Unfold.html#TooBig"><span class="hs-identifier hs-var">TooBig</span></a></span><span>          </span><span class="annot"><span class="annottext">Int
</span><span class="hs-identifier">_</span></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">ExprSize
</span><a href="GHC.Core.Unfold.html#TooBig"><span class="hs-identifier hs-var">TooBig</span></a></span><span>
</span><span id="line-781"></span><span>    </span><span class="annot"><a href="#local-6989586621680863749"><span class="hs-identifier hs-var">addSizeN</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.Unfold.html#SizeIs"><span class="hs-identifier hs-type">SizeIs</span></a></span><span> </span><span id="local-6989586621680863639"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863639"><span class="hs-identifier hs-var">n</span></a></span></span><span> </span><span id="local-6989586621680863638"><span class="annot"><span class="annottext">Bag (Id, Int)
</span><a href="#local-6989586621680863638"><span class="hs-identifier hs-var">xs</span></a></span></span><span> </span><span id="local-6989586621680863637"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863637"><span class="hs-identifier hs-var">d</span></a></span></span><span class="hs-special">)</span><span> </span><span id="local-6989586621680863636"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863636"><span class="hs-identifier hs-var">m</span></a></span></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Bag (Id, Int) -&gt; Int -&gt; ExprSize
</span><a href="GHC.Core.Unfold.html#mkSizeIs"><span class="hs-identifier hs-var">mkSizeIs</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863787"><span class="hs-identifier hs-var">bOMB_OUT_SIZE</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863639"><span class="hs-identifier hs-var">n</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="../../base/src/GHC.Num.html#%2B"><span class="hs-operator hs-var">+</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863636"><span class="hs-identifier hs-var">m</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Bag (Id, Int)
</span><a href="#local-6989586621680863638"><span class="hs-identifier hs-var">xs</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863637"><span class="hs-identifier hs-var">d</span></a></span><span>
</span><span id="line-782"></span><span>
</span><span id="line-783"></span><span>        </span><span class="hs-comment">-- addAltSize is used to add the sizes of case alternatives</span><span>
</span><span id="line-784"></span><span>    </span><span id="local-6989586621680863714"><span class="annot"><span class="annottext">addAltSize :: ExprSize -&gt; ExprSize -&gt; ExprSize
</span><a href="#local-6989586621680863714"><span class="hs-identifier hs-var hs-var">addAltSize</span></a></span></span><span> </span><span class="annot"><span class="annottext">ExprSize
</span><a href="GHC.Core.Unfold.html#TooBig"><span class="hs-identifier hs-var">TooBig</span></a></span><span>            </span><span class="annot"><span class="annottext">ExprSize
</span><span class="hs-identifier">_</span></span><span>      </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">ExprSize
</span><a href="GHC.Core.Unfold.html#TooBig"><span class="hs-identifier hs-var">TooBig</span></a></span><span>
</span><span id="line-785"></span><span>    </span><span class="annot"><a href="#local-6989586621680863714"><span class="hs-identifier hs-var">addAltSize</span></a></span><span> </span><span class="annot"><span class="annottext">ExprSize
</span><span class="hs-identifier">_</span></span><span>                 </span><span class="annot"><span class="annottext">ExprSize
</span><a href="GHC.Core.Unfold.html#TooBig"><span class="hs-identifier hs-var">TooBig</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">ExprSize
</span><a href="GHC.Core.Unfold.html#TooBig"><span class="hs-identifier hs-var">TooBig</span></a></span><span>
</span><span id="line-786"></span><span>    </span><span class="annot"><a href="#local-6989586621680863714"><span class="hs-identifier hs-var">addAltSize</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.Unfold.html#SizeIs"><span class="hs-identifier hs-type">SizeIs</span></a></span><span> </span><span id="local-6989586621680863632"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863632"><span class="hs-identifier hs-var">n1</span></a></span></span><span> </span><span id="local-6989586621680863631"><span class="annot"><span class="annottext">Bag (Id, Int)
</span><a href="#local-6989586621680863631"><span class="hs-identifier hs-var">xs</span></a></span></span><span> </span><span id="local-6989586621680863630"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863630"><span class="hs-identifier hs-var">d1</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.Unfold.html#SizeIs"><span class="hs-identifier hs-type">SizeIs</span></a></span><span> </span><span id="local-6989586621680863629"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863629"><span class="hs-identifier hs-var">n2</span></a></span></span><span> </span><span id="local-6989586621680863628"><span class="annot"><span class="annottext">Bag (Id, Int)
</span><a href="#local-6989586621680863628"><span class="hs-identifier hs-var">ys</span></a></span></span><span> </span><span id="local-6989586621680863627"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863627"><span class="hs-identifier hs-var">d2</span></a></span></span><span class="hs-special">)</span><span>
</span><span id="line-787"></span><span>        </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Bag (Id, Int) -&gt; Int -&gt; ExprSize
</span><a href="GHC.Core.Unfold.html#mkSizeIs"><span class="hs-identifier hs-var">mkSizeIs</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863787"><span class="hs-identifier hs-var">bOMB_OUT_SIZE</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863632"><span class="hs-identifier hs-var">n1</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="../../base/src/GHC.Num.html#%2B"><span class="hs-operator hs-var">+</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863629"><span class="hs-identifier hs-var">n2</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-788"></span><span>                                 </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Bag (Id, Int)
</span><a href="#local-6989586621680863631"><span class="hs-identifier hs-var">xs</span></a></span><span> </span><span class="annot"><span class="annottext">Bag (Id, Int) -&gt; Bag (Id, Int) -&gt; Bag (Id, Int)
forall a. Bag a -&gt; Bag a -&gt; Bag a
</span><a href="GHC.Data.Bag.html#unionBags"><span class="hs-operator hs-var">`unionBags`</span></a></span><span> </span><span class="annot"><span class="annottext">Bag (Id, Int)
</span><a href="#local-6989586621680863628"><span class="hs-identifier hs-var">ys</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-789"></span><span>                                 </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863630"><span class="hs-identifier hs-var">d1</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="../../base/src/GHC.Num.html#%2B"><span class="hs-operator hs-var">+</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863627"><span class="hs-identifier hs-var">d2</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-comment">-- Note [addAltSize result discounts]</span><span>
</span><span id="line-790"></span><span>
</span><span id="line-791"></span><span>        </span><span class="hs-comment">-- This variant ignores the result discount from its LEFT argument</span><span>
</span><span id="line-792"></span><span>        </span><span class="hs-comment">-- It's used when the second argument isn't part of the result</span><span>
</span><span id="line-793"></span><span>    </span><span id="local-6989586621680863755"><span class="annot"><span class="annottext">addSizeNSD :: ExprSize -&gt; ExprSize -&gt; ExprSize
</span><a href="#local-6989586621680863755"><span class="hs-identifier hs-var hs-var">addSizeNSD</span></a></span></span><span> </span><span class="annot"><span class="annottext">ExprSize
</span><a href="GHC.Core.Unfold.html#TooBig"><span class="hs-identifier hs-var">TooBig</span></a></span><span>            </span><span class="annot"><span class="annottext">ExprSize
</span><span class="hs-identifier">_</span></span><span>      </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">ExprSize
</span><a href="GHC.Core.Unfold.html#TooBig"><span class="hs-identifier hs-var">TooBig</span></a></span><span>
</span><span id="line-794"></span><span>    </span><span class="annot"><a href="#local-6989586621680863755"><span class="hs-identifier hs-var">addSizeNSD</span></a></span><span> </span><span class="annot"><span class="annottext">ExprSize
</span><span class="hs-identifier">_</span></span><span>                 </span><span class="annot"><span class="annottext">ExprSize
</span><a href="GHC.Core.Unfold.html#TooBig"><span class="hs-identifier hs-var">TooBig</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">ExprSize
</span><a href="GHC.Core.Unfold.html#TooBig"><span class="hs-identifier hs-var">TooBig</span></a></span><span>
</span><span id="line-795"></span><span>    </span><span class="annot"><a href="#local-6989586621680863755"><span class="hs-identifier hs-var">addSizeNSD</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.Unfold.html#SizeIs"><span class="hs-identifier hs-type">SizeIs</span></a></span><span> </span><span id="local-6989586621680863625"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863625"><span class="hs-identifier hs-var">n1</span></a></span></span><span> </span><span id="local-6989586621680863624"><span class="annot"><span class="annottext">Bag (Id, Int)
</span><a href="#local-6989586621680863624"><span class="hs-identifier hs-var">xs</span></a></span></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-identifier">_</span></span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.Unfold.html#SizeIs"><span class="hs-identifier hs-type">SizeIs</span></a></span><span> </span><span id="local-6989586621680863623"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863623"><span class="hs-identifier hs-var">n2</span></a></span></span><span> </span><span id="local-6989586621680863622"><span class="annot"><span class="annottext">Bag (Id, Int)
</span><a href="#local-6989586621680863622"><span class="hs-identifier hs-var">ys</span></a></span></span><span> </span><span id="local-6989586621680863621"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863621"><span class="hs-identifier hs-var">d2</span></a></span></span><span class="hs-special">)</span><span>
</span><span id="line-796"></span><span>        </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Bag (Id, Int) -&gt; Int -&gt; ExprSize
</span><a href="GHC.Core.Unfold.html#mkSizeIs"><span class="hs-identifier hs-var">mkSizeIs</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863787"><span class="hs-identifier hs-var">bOMB_OUT_SIZE</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863625"><span class="hs-identifier hs-var">n1</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="../../base/src/GHC.Num.html#%2B"><span class="hs-operator hs-var">+</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863623"><span class="hs-identifier hs-var">n2</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-797"></span><span>                                 </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Bag (Id, Int)
</span><a href="#local-6989586621680863624"><span class="hs-identifier hs-var">xs</span></a></span><span> </span><span class="annot"><span class="annottext">Bag (Id, Int) -&gt; Bag (Id, Int) -&gt; Bag (Id, Int)
forall a. Bag a -&gt; Bag a -&gt; Bag a
</span><a href="GHC.Data.Bag.html#unionBags"><span class="hs-operator hs-var">`unionBags`</span></a></span><span> </span><span class="annot"><span class="annottext">Bag (Id, Int)
</span><a href="#local-6989586621680863622"><span class="hs-identifier hs-var">ys</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-798"></span><span>                                 </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863621"><span class="hs-identifier hs-var">d2</span></a></span><span>  </span><span class="hs-comment">-- Ignore d1</span><span>
</span><span id="line-799"></span><span>
</span><span id="line-800"></span><span>    </span><span id="local-6989586621680863760"><span class="annot"><span class="annottext">isRealWorldId :: Id -&gt; Bool
</span><a href="#local-6989586621680863760"><span class="hs-identifier hs-var hs-var">isRealWorldId</span></a></span></span><span> </span><span id="local-6989586621680863620"><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680863620"><span class="hs-identifier hs-var">id</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Id -&gt; Type
</span><a href="GHC.Types.Id.html#idType"><span class="hs-identifier hs-var">idType</span></a></span><span> </span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680863620"><span class="hs-identifier hs-var">id</span></a></span><span> </span><span class="annot"><span class="annottext">Type -&gt; Type -&gt; Bool
</span><a href="GHC.Core.Type.html#eqType"><span class="hs-operator hs-var">`eqType`</span></a></span><span> </span><span class="annot"><span class="annottext">Type
</span><a href="GHC.Builtin.Types.Prim.html#realWorldStatePrimTy"><span class="hs-identifier hs-var">realWorldStatePrimTy</span></a></span><span>
</span><span id="line-801"></span><span>
</span><span id="line-802"></span><span>    </span><span class="hs-comment">-- an expression of type State# RealWorld must be a variable</span><span>
</span><span id="line-803"></span><span>    </span><span id="local-6989586621680863753"><span class="annot"><span class="annottext">isRealWorldExpr :: Expr b -&gt; Bool
</span><a href="#local-6989586621680863753"><span class="hs-identifier hs-var hs-var">isRealWorldExpr</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#Var"><span class="hs-identifier hs-type">Var</span></a></span><span> </span><span id="local-6989586621680863618"><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680863618"><span class="hs-identifier hs-var">id</span></a></span></span><span class="hs-special">)</span><span>   </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Id -&gt; Bool
</span><a href="#local-6989586621680863760"><span class="hs-identifier hs-var">isRealWorldId</span></a></span><span> </span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680863618"><span class="hs-identifier hs-var">id</span></a></span><span>
</span><span id="line-804"></span><span>    </span><span class="annot"><a href="#local-6989586621680863753"><span class="hs-identifier hs-var">isRealWorldExpr</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#Tick"><span class="hs-identifier hs-type">Tick</span></a></span><span> </span><span class="annot"><span class="annottext">Tickish Id
</span><span class="hs-identifier">_</span></span><span> </span><span id="local-6989586621680863617"><span class="annot"><span class="annottext">Expr b
</span><a href="#local-6989586621680863617"><span class="hs-identifier hs-var">e</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Expr b -&gt; Bool
</span><a href="#local-6989586621680863753"><span class="hs-identifier hs-var">isRealWorldExpr</span></a></span><span> </span><span class="annot"><span class="annottext">Expr b
</span><a href="#local-6989586621680863617"><span class="hs-identifier hs-var">e</span></a></span><span>
</span><span id="line-805"></span><span>    </span><span class="annot"><a href="#local-6989586621680863753"><span class="hs-identifier hs-var">isRealWorldExpr</span></a></span><span> </span><span class="annot"><span class="annottext">Expr b
</span><span class="hs-identifier">_</span></span><span>          </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">False</span></span><span>
</span><span id="line-806"></span><span>
</span><span id="line-807"></span><span class="hs-comment">-- | Finds a nominal size of a string literal.</span><span>
</span><span id="line-808"></span><span class="annot"><a href="GHC.Core.Unfold.html#litSize"><span class="hs-identifier hs-type">litSize</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Types.Literal.html#Literal"><span class="hs-identifier hs-type">Literal</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Int</span></span><span>
</span><span id="line-809"></span><span class="hs-comment">-- Used by GHC.Core.Unfold.sizeExpr</span><span>
</span><span id="line-810"></span><span id="litSize"><span class="annot"><span class="annottext">litSize :: Literal -&gt; Int
</span><a href="GHC.Core.Unfold.html#litSize"><span class="hs-identifier hs-var hs-var">litSize</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Types.Literal.html#LitNumber"><span class="hs-identifier hs-type">LitNumber</span></a></span><span> </span><span class="annot"><span class="annottext">LitNumType
</span><a href="GHC.Types.Literal.html#LitNumInteger"><span class="hs-identifier hs-var">LitNumInteger</span></a></span><span> </span><span class="annot"><span class="annottext">Integer
</span><span class="hs-identifier">_</span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">100</span></span><span>   </span><span class="hs-comment">-- Note [Size of literal integers]</span><span>
</span><span id="line-811"></span><span class="annot"><a href="GHC.Core.Unfold.html#litSize"><span class="hs-identifier hs-var">litSize</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Types.Literal.html#LitNumber"><span class="hs-identifier hs-type">LitNumber</span></a></span><span> </span><span class="annot"><span class="annottext">LitNumType
</span><a href="GHC.Types.Literal.html#LitNumNatural"><span class="hs-identifier hs-var">LitNumNatural</span></a></span><span> </span><span class="annot"><span class="annottext">Integer
</span><span class="hs-identifier">_</span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">100</span></span><span>
</span><span id="line-812"></span><span class="annot"><a href="GHC.Core.Unfold.html#litSize"><span class="hs-identifier hs-var">litSize</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Types.Literal.html#LitString"><span class="hs-identifier hs-type">LitString</span></a></span><span> </span><span id="local-6989586621680863612"><span class="annot"><span class="annottext">ByteString
</span><a href="#local-6989586621680863612"><span class="hs-identifier hs-var">str</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">10</span></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="../../base/src/GHC.Num.html#%2B"><span class="hs-operator hs-var">+</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">10</span></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="../../base/src/GHC.Num.html#%2A"><span class="hs-operator hs-var">*</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">(</span><span class="annot"><span class="annottext">ByteString -&gt; Int
</span><a href="../../bytestring/src/Data.ByteString.html#length"><span class="hs-identifier hs-var">BS.length</span></a></span><span> </span><span class="annot"><span class="annottext">ByteString
</span><a href="#local-6989586621680863612"><span class="hs-identifier hs-var">str</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="../../base/src/GHC.Num.html#%2B"><span class="hs-operator hs-var">+</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">3</span></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Integral a =&gt; a -&gt; a -&gt; a
</span><a href="../../base/src/GHC.Real.html#div"><span class="hs-operator hs-var">`div`</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">4</span></span><span class="hs-special">)</span><span>
</span><span id="line-813"></span><span>        </span><span class="hs-comment">-- If size could be 0 then @f &quot;x&quot;@ might be too small</span><span>
</span><span id="line-814"></span><span>        </span><span class="hs-comment">-- [Sept03: make literal strings a bit bigger to avoid fruitless</span><span>
</span><span id="line-815"></span><span>        </span><span class="hs-comment">--  duplication of little strings]</span><span>
</span><span id="line-816"></span><span class="annot"><a href="GHC.Core.Unfold.html#litSize"><span class="hs-identifier hs-var">litSize</span></a></span><span> </span><span id="local-6989586621680863609"><span class="annot"><span class="annottext">Literal
</span><a href="#local-6989586621680863609"><span class="hs-identifier hs-var">_other</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">0</span></span><span>    </span><span class="hs-comment">-- Must match size of nullary constructors</span><span>
</span><span id="line-817"></span><span>                      </span><span class="hs-comment">-- Key point: if  x |-&gt; 4, then x must inline unconditionally</span><span>
</span><span id="line-818"></span><span>                      </span><span class="hs-comment">--            (eg via case binding)</span><span>
</span><span id="line-819"></span><span>
</span><span id="line-820"></span><span class="annot"><a href="GHC.Core.Unfold.html#classOpSize"><span class="hs-identifier hs-type">classOpSize</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Driver.Session.html#DynFlags"><span class="hs-identifier hs-type">DynFlags</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Types.Var.html#Id"><span class="hs-identifier hs-type">Id</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.html#CoreExpr"><span class="hs-identifier hs-type">CoreExpr</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.Unfold.html#ExprSize"><span class="hs-identifier hs-type">ExprSize</span></a></span><span>
</span><span id="line-821"></span><span class="hs-comment">-- See Note [Conlike is interesting]</span><span>
</span><span id="line-822"></span><span id="classOpSize"><span class="annot"><span class="annottext">classOpSize :: DynFlags -&gt; [Id] -&gt; [CoreArg] -&gt; ExprSize
</span><a href="GHC.Core.Unfold.html#classOpSize"><span class="hs-identifier hs-var hs-var">classOpSize</span></a></span></span><span> </span><span class="annot"><span class="annottext">DynFlags
</span><span class="hs-identifier">_</span></span><span> </span><span class="annot"><span class="annottext">[Id]
</span><span class="hs-identifier">_</span></span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span>
</span><span id="line-823"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">ExprSize
</span><a href="GHC.Core.Unfold.html#sizeZero"><span class="hs-identifier hs-var">sizeZero</span></a></span><span>
</span><span id="line-824"></span><span class="annot"><a href="GHC.Core.Unfold.html#classOpSize"><span class="hs-identifier hs-var">classOpSize</span></a></span><span> </span><span id="local-6989586621680863608"><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680863608"><span class="hs-identifier hs-var">dflags</span></a></span></span><span> </span><span id="local-6989586621680863607"><span class="annot"><span class="annottext">[Id]
</span><a href="#local-6989586621680863607"><span class="hs-identifier hs-var">top_args</span></a></span></span><span> </span><span class="hs-special">(</span><span id="local-6989586621680863606"><span class="annot"><span class="annottext">CoreArg
</span><a href="#local-6989586621680863606"><span class="hs-identifier hs-var">arg1</span></a></span></span><span> </span><span class="annot"><span class="hs-glyph hs-type">:</span></span><span> </span><span id="local-6989586621680863605"><span class="annot"><span class="annottext">[CoreArg]
</span><a href="#local-6989586621680863605"><span class="hs-identifier hs-var">other_args</span></a></span></span><span class="hs-special">)</span><span>
</span><span id="line-825"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int -&gt; Bag (Id, Int) -&gt; Int -&gt; ExprSize
</span><a href="GHC.Core.Unfold.html#SizeIs"><span class="hs-identifier hs-var">SizeIs</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863604"><span class="hs-identifier hs-var">size</span></a></span><span> </span><span class="annot"><span class="annottext">Bag (Id, Int)
</span><a href="#local-6989586621680863603"><span class="hs-identifier hs-var">arg_discount</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">0</span></span><span>
</span><span id="line-826"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-827"></span><span>    </span><span id="local-6989586621680863604"><span class="annot"><span class="annottext">size :: Int
</span><a href="#local-6989586621680863604"><span class="hs-identifier hs-var hs-var">size</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">20</span></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="../../base/src/GHC.Num.html#%2B"><span class="hs-operator hs-var">+</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">10</span></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="../../base/src/GHC.Num.html#%2A"><span class="hs-operator hs-var">*</span></a></span><span> </span><span class="annot"><span class="annottext">[CoreArg] -&gt; Int
forall (t :: * -&gt; *) a. Foldable t =&gt; t a -&gt; Int
</span><a href="../../base/src/Data.Foldable.html#length"><span class="hs-identifier hs-var">length</span></a></span><span> </span><span class="annot"><span class="annottext">[CoreArg]
</span><a href="#local-6989586621680863605"><span class="hs-identifier hs-var">other_args</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-828"></span><span>    </span><span class="hs-comment">-- If the class op is scrutinising a lambda bound dictionary then</span><span>
</span><span id="line-829"></span><span>    </span><span class="hs-comment">-- give it a discount, to encourage the inlining of this function</span><span>
</span><span id="line-830"></span><span>    </span><span class="hs-comment">-- The actual discount is rather arbitrarily chosen</span><span>
</span><span id="line-831"></span><span>    </span><span id="local-6989586621680863603"><span class="annot"><span class="annottext">arg_discount :: Bag (Id, Int)
</span><a href="#local-6989586621680863603"><span class="hs-identifier hs-var hs-var">arg_discount</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">CoreArg
</span><a href="#local-6989586621680863606"><span class="hs-identifier hs-var">arg1</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-832"></span><span>                     </span><span class="annot"><a href="GHC.Core.html#Var"><span class="hs-identifier hs-type">Var</span></a></span><span> </span><span id="local-6989586621680863595"><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680863595"><span class="hs-identifier hs-var">dict</span></a></span></span><span> </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680863595"><span class="hs-identifier hs-var">dict</span></a></span><span> </span><span class="annot"><span class="annottext">Id -&gt; [Id] -&gt; Bool
forall (t :: * -&gt; *) a. (Foldable t, Eq a) =&gt; a -&gt; t a -&gt; Bool
</span><a href="../../base/src/Data.Foldable.html#elem"><span class="hs-operator hs-var">`elem`</span></a></span><span> </span><span class="annot"><span class="annottext">[Id]
</span><a href="#local-6989586621680863607"><span class="hs-identifier hs-var">top_args</span></a></span><span>
</span><span id="line-833"></span><span>                              </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">(Id, Int) -&gt; Bag (Id, Int)
forall a. a -&gt; Bag a
</span><a href="GHC.Data.Bag.html#unitBag"><span class="hs-identifier hs-var">unitBag</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680863595"><span class="hs-identifier hs-var">dict</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">DynFlags -&gt; Int
</span><a href="GHC.Driver.Session.html#ufDictDiscount"><span class="hs-identifier hs-var hs-var">ufDictDiscount</span></a></span><span> </span><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680863608"><span class="hs-identifier hs-var">dflags</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-834"></span><span>                     </span><span id="local-6989586621680863593"><span class="annot"><span class="annottext">CoreArg
</span><a href="#local-6989586621680863593"><span class="hs-identifier hs-var">_other</span></a></span></span><span>   </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Bag (Id, Int)
forall a. Bag a
</span><a href="GHC.Data.Bag.html#emptyBag"><span class="hs-identifier hs-var">emptyBag</span></a></span><span>
</span><span id="line-835"></span><span>
</span><span id="line-836"></span><span class="hs-comment">-- | The size of a function call</span><span>
</span><span id="line-837"></span><span class="annot"><a href="GHC.Core.Unfold.html#callSize"><span class="hs-identifier hs-type">callSize</span></a></span><span>
</span><span id="line-838"></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Int</span></span><span>  </span><span class="hs-comment">-- ^ number of value args</span><span>
</span><span id="line-839"></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Int</span></span><span>  </span><span class="hs-comment">-- ^ number of value args that are void</span><span>
</span><span id="line-840"></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Int</span></span><span>
</span><span id="line-841"></span><span id="callSize"><span class="annot"><span class="annottext">callSize :: Int -&gt; Int -&gt; Int
</span><a href="GHC.Core.Unfold.html#callSize"><span class="hs-identifier hs-var hs-var">callSize</span></a></span></span><span> </span><span id="local-6989586621680863591"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863591"><span class="hs-identifier hs-var">n_val_args</span></a></span></span><span> </span><span id="local-6989586621680863590"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863590"><span class="hs-identifier hs-var">voids</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">10</span></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="../../base/src/GHC.Num.html#%2A"><span class="hs-operator hs-var">*</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">1</span></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="../../base/src/GHC.Num.html#%2B"><span class="hs-operator hs-var">+</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863591"><span class="hs-identifier hs-var">n_val_args</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="../../base/src/GHC.Num.html#-"><span class="hs-glyph hs-var">-</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863590"><span class="hs-identifier hs-var">voids</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-842"></span><span>        </span><span class="hs-comment">-- The 1+ is for the function itself</span><span>
</span><span id="line-843"></span><span>        </span><span class="hs-comment">-- Add 1 for each non-trivial arg;</span><span>
</span><span id="line-844"></span><span>        </span><span class="hs-comment">-- the allocation cost, as in let(rec)</span><span>
</span><span id="line-845"></span><span>
</span><span id="line-846"></span><span class="hs-comment">-- | The size of a jump to a join point</span><span>
</span><span id="line-847"></span><span class="annot"><a href="GHC.Core.Unfold.html#jumpSize"><span class="hs-identifier hs-type">jumpSize</span></a></span><span>
</span><span id="line-848"></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Int</span></span><span>  </span><span class="hs-comment">-- ^ number of value args</span><span>
</span><span id="line-849"></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Int</span></span><span>  </span><span class="hs-comment">-- ^ number of value args that are void</span><span>
</span><span id="line-850"></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Int</span></span><span>
</span><span id="line-851"></span><span id="jumpSize"><span class="annot"><span class="annottext">jumpSize :: Int -&gt; Int -&gt; Int
</span><a href="GHC.Core.Unfold.html#jumpSize"><span class="hs-identifier hs-var hs-var">jumpSize</span></a></span></span><span> </span><span id="local-6989586621680863588"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863588"><span class="hs-identifier hs-var">n_val_args</span></a></span></span><span> </span><span id="local-6989586621680863587"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863587"><span class="hs-identifier hs-var">voids</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">2</span></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="../../base/src/GHC.Num.html#%2A"><span class="hs-operator hs-var">*</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">1</span></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="../../base/src/GHC.Num.html#%2B"><span class="hs-operator hs-var">+</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863588"><span class="hs-identifier hs-var">n_val_args</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="../../base/src/GHC.Num.html#-"><span class="hs-glyph hs-var">-</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863587"><span class="hs-identifier hs-var">voids</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-852"></span><span>  </span><span class="hs-comment">-- A jump is 20% the size of a function call. Making jumps free reopens</span><span>
</span><span id="line-853"></span><span>  </span><span class="hs-comment">-- bug #6048, but making them any more expensive loses a 21% improvement in</span><span>
</span><span id="line-854"></span><span>  </span><span class="hs-comment">-- spectral/puzzle. TODO Perhaps adjusting the default threshold would be a</span><span>
</span><span id="line-855"></span><span>  </span><span class="hs-comment">-- better solution?</span><span>
</span><span id="line-856"></span><span>
</span><span id="line-857"></span><span class="annot"><a href="GHC.Core.Unfold.html#funSize"><span class="hs-identifier hs-type">funSize</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Driver.Session.html#DynFlags"><span class="hs-identifier hs-type">DynFlags</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Types.Var.html#Id"><span class="hs-identifier hs-type">Id</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Types.Var.html#Id"><span class="hs-identifier hs-type">Id</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Int</span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Int</span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.Unfold.html#ExprSize"><span class="hs-identifier hs-type">ExprSize</span></a></span><span>
</span><span id="line-858"></span><span class="hs-comment">-- Size for functions that are not constructors or primops</span><span>
</span><span id="line-859"></span><span class="hs-comment">-- Note [Function applications]</span><span>
</span><span id="line-860"></span><span id="funSize"><span class="annot"><span class="annottext">funSize :: DynFlags -&gt; [Id] -&gt; Id -&gt; Int -&gt; Int -&gt; ExprSize
</span><a href="GHC.Core.Unfold.html#funSize"><span class="hs-identifier hs-var hs-var">funSize</span></a></span></span><span> </span><span id="local-6989586621680863586"><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680863586"><span class="hs-identifier hs-var">dflags</span></a></span></span><span> </span><span id="local-6989586621680863585"><span class="annot"><span class="annottext">[Id]
</span><a href="#local-6989586621680863585"><span class="hs-identifier hs-var">top_args</span></a></span></span><span> </span><span id="local-6989586621680863584"><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680863584"><span class="hs-identifier hs-var">fun</span></a></span></span><span> </span><span id="local-6989586621680863583"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863583"><span class="hs-identifier hs-var">n_val_args</span></a></span></span><span> </span><span id="local-6989586621680863582"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863582"><span class="hs-identifier hs-var">voids</span></a></span></span><span>
</span><span id="line-861"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680863584"><span class="hs-identifier hs-var">fun</span></a></span><span> </span><span class="annot"><span class="annottext">Id -&gt; Unique -&gt; Bool
forall a. Uniquable a =&gt; a -&gt; Unique -&gt; Bool
</span><a href="GHC.Types.Unique.html#hasKey"><span class="hs-operator hs-var">`hasKey`</span></a></span><span> </span><span class="annot"><span class="annottext">Unique
</span><a href="GHC.Builtin.Names.html#buildIdKey"><span class="hs-identifier hs-var">buildIdKey</span></a></span><span>   </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">ExprSize
</span><a href="GHC.Core.Unfold.html#buildSize"><span class="hs-identifier hs-var">buildSize</span></a></span><span>
</span><span id="line-862"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680863584"><span class="hs-identifier hs-var">fun</span></a></span><span> </span><span class="annot"><span class="annottext">Id -&gt; Unique -&gt; Bool
forall a. Uniquable a =&gt; a -&gt; Unique -&gt; Bool
</span><a href="GHC.Types.Unique.html#hasKey"><span class="hs-operator hs-var">`hasKey`</span></a></span><span> </span><span class="annot"><span class="annottext">Unique
</span><a href="GHC.Builtin.Names.html#augmentIdKey"><span class="hs-identifier hs-var">augmentIdKey</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">ExprSize
</span><a href="GHC.Core.Unfold.html#augmentSize"><span class="hs-identifier hs-var">augmentSize</span></a></span><span>
</span><span id="line-863"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int -&gt; Bag (Id, Int) -&gt; Int -&gt; ExprSize
</span><a href="GHC.Core.Unfold.html#SizeIs"><span class="hs-identifier hs-var">SizeIs</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863576"><span class="hs-identifier hs-var">size</span></a></span><span> </span><span class="annot"><span class="annottext">Bag (Id, Int)
</span><a href="#local-6989586621680863575"><span class="hs-identifier hs-var">arg_discount</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863574"><span class="hs-identifier hs-var">res_discount</span></a></span><span>
</span><span id="line-864"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-865"></span><span>    </span><span id="local-6989586621680863571"><span class="annot"><span class="annottext">some_val_args :: Bool
</span><a href="#local-6989586621680863571"><span class="hs-identifier hs-var hs-var">some_val_args</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863583"><span class="hs-identifier hs-var">n_val_args</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Bool
forall a. Ord a =&gt; a -&gt; a -&gt; Bool
</span><span class="hs-operator hs-var">&gt;</span></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">0</span></span><span>
</span><span id="line-866"></span><span>    </span><span id="local-6989586621680863570"><span class="annot"><span class="annottext">is_join :: Bool
</span><a href="#local-6989586621680863570"><span class="hs-identifier hs-var hs-var">is_join</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Id -&gt; Bool
</span><a href="GHC.Types.Id.html#isJoinId"><span class="hs-identifier hs-var">isJoinId</span></a></span><span> </span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680863584"><span class="hs-identifier hs-var">fun</span></a></span><span>
</span><span id="line-867"></span><span>
</span><span id="line-868"></span><span>    </span><span id="local-6989586621680863576"><span class="annot"><span class="annottext">size :: Int
</span><a href="#local-6989586621680863576"><span class="hs-identifier hs-var hs-var">size</span></a></span></span><span> </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621680863570"><span class="hs-identifier hs-var">is_join</span></a></span><span>              </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
</span><a href="GHC.Core.Unfold.html#jumpSize"><span class="hs-identifier hs-var">jumpSize</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863583"><span class="hs-identifier hs-var">n_val_args</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863582"><span class="hs-identifier hs-var">voids</span></a></span><span>
</span><span id="line-869"></span><span>         </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Bool
</span><span class="hs-identifier hs-var">not</span></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621680863571"><span class="hs-identifier hs-var">some_val_args</span></a></span><span>    </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">0</span></span><span>
</span><span id="line-870"></span><span>         </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span>            </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
</span><a href="GHC.Core.Unfold.html#callSize"><span class="hs-identifier hs-var">callSize</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863583"><span class="hs-identifier hs-var">n_val_args</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863582"><span class="hs-identifier hs-var">voids</span></a></span><span>
</span><span id="line-871"></span><span>
</span><span id="line-872"></span><span>        </span><span class="hs-comment">--                  DISCOUNTS</span><span>
</span><span id="line-873"></span><span>        </span><span class="hs-comment">--  See Note [Function and non-function discounts]</span><span>
</span><span id="line-874"></span><span>    </span><span id="local-6989586621680863575"><span class="annot"><span class="annottext">arg_discount :: Bag (Id, Int)
</span><a href="#local-6989586621680863575"><span class="hs-identifier hs-var hs-var">arg_discount</span></a></span></span><span> </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621680863571"><span class="hs-identifier hs-var">some_val_args</span></a></span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Bool -&gt; Bool
</span><span class="hs-operator hs-var">&amp;&amp;</span></span><span> </span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680863584"><span class="hs-identifier hs-var">fun</span></a></span><span> </span><span class="annot"><span class="annottext">Id -&gt; [Id] -&gt; Bool
forall (t :: * -&gt; *) a. (Foldable t, Eq a) =&gt; a -&gt; t a -&gt; Bool
</span><a href="../../base/src/Data.Foldable.html#elem"><span class="hs-operator hs-var">`elem`</span></a></span><span> </span><span class="annot"><span class="annottext">[Id]
</span><a href="#local-6989586621680863585"><span class="hs-identifier hs-var">top_args</span></a></span><span>
</span><span id="line-875"></span><span>                 </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(Id, Int) -&gt; Bag (Id, Int)
forall a. a -&gt; Bag a
</span><a href="GHC.Data.Bag.html#unitBag"><span class="hs-identifier hs-var">unitBag</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680863584"><span class="hs-identifier hs-var">fun</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">DynFlags -&gt; Int
</span><a href="GHC.Driver.Session.html#ufFunAppDiscount"><span class="hs-identifier hs-var hs-var">ufFunAppDiscount</span></a></span><span> </span><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680863586"><span class="hs-identifier hs-var">dflags</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-876"></span><span>                 </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bag (Id, Int)
forall a. Bag a
</span><a href="GHC.Data.Bag.html#emptyBag"><span class="hs-identifier hs-var">emptyBag</span></a></span><span>
</span><span id="line-877"></span><span>        </span><span class="hs-comment">-- If the function is an argument and is applied</span><span>
</span><span id="line-878"></span><span>        </span><span class="hs-comment">-- to some values, give it an arg-discount</span><span>
</span><span id="line-879"></span><span>
</span><span id="line-880"></span><span>    </span><span id="local-6989586621680863574"><span class="annot"><span class="annottext">res_discount :: Int
</span><a href="#local-6989586621680863574"><span class="hs-identifier hs-var hs-var">res_discount</span></a></span></span><span> </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Id -&gt; Int
</span><a href="GHC.Types.Id.html#idArity"><span class="hs-identifier hs-var">idArity</span></a></span><span> </span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680863584"><span class="hs-identifier hs-var">fun</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Bool
forall a. Ord a =&gt; a -&gt; a -&gt; Bool
</span><span class="hs-operator hs-var">&gt;</span></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863583"><span class="hs-identifier hs-var">n_val_args</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">DynFlags -&gt; Int
</span><a href="GHC.Driver.Session.html#ufFunAppDiscount"><span class="hs-identifier hs-var hs-var">ufFunAppDiscount</span></a></span><span> </span><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680863586"><span class="hs-identifier hs-var">dflags</span></a></span><span>
</span><span id="line-881"></span><span>                 </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span>                </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">0</span></span><span>
</span><span id="line-882"></span><span>        </span><span class="hs-comment">-- If the function is partially applied, show a result discount</span><span>
</span><span id="line-883"></span><span class="hs-comment">-- XXX maybe behave like ConSize for eval'd variable</span><span>
</span><span id="line-884"></span><span>
</span><span id="line-885"></span><span class="annot"><a href="GHC.Core.Unfold.html#conSize"><span class="hs-identifier hs-type">conSize</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.DataCon.html#DataCon"><span class="hs-identifier hs-type">DataCon</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Int</span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.Unfold.html#ExprSize"><span class="hs-identifier hs-type">ExprSize</span></a></span><span>
</span><span id="line-886"></span><span id="conSize"><span class="annot"><span class="annottext">conSize :: DataCon -&gt; Int -&gt; ExprSize
</span><a href="GHC.Core.Unfold.html#conSize"><span class="hs-identifier hs-var hs-var">conSize</span></a></span></span><span> </span><span id="local-6989586621680863564"><span class="annot"><span class="annottext">DataCon
</span><a href="#local-6989586621680863564"><span class="hs-identifier hs-var">dc</span></a></span></span><span> </span><span id="local-6989586621680863563"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863563"><span class="hs-identifier hs-var">n_val_args</span></a></span></span><span>
</span><span id="line-887"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863563"><span class="hs-identifier hs-var">n_val_args</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Bool
forall a. Eq a =&gt; a -&gt; a -&gt; Bool
</span><span class="hs-operator hs-var">==</span></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">0</span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int -&gt; Bag (Id, Int) -&gt; Int -&gt; ExprSize
</span><a href="GHC.Core.Unfold.html#SizeIs"><span class="hs-identifier hs-var">SizeIs</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">0</span></span><span> </span><span class="annot"><span class="annottext">Bag (Id, Int)
forall a. Bag a
</span><a href="GHC.Data.Bag.html#emptyBag"><span class="hs-identifier hs-var">emptyBag</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">10</span></span><span>    </span><span class="hs-comment">-- Like variables</span><span>
</span><span id="line-888"></span><span>
</span><span id="line-889"></span><span class="hs-comment">-- See Note [Unboxed tuple size and result discount]</span><span>
</span><span id="line-890"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">DataCon -&gt; Bool
</span><a href="GHC.Core.DataCon.html#isUnboxedTupleCon"><span class="hs-identifier hs-var">isUnboxedTupleCon</span></a></span><span> </span><span class="annot"><span class="annottext">DataCon
</span><a href="#local-6989586621680863564"><span class="hs-identifier hs-var">dc</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int -&gt; Bag (Id, Int) -&gt; Int -&gt; ExprSize
</span><a href="GHC.Core.Unfold.html#SizeIs"><span class="hs-identifier hs-var">SizeIs</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">0</span></span><span> </span><span class="annot"><span class="annottext">Bag (Id, Int)
forall a. Bag a
</span><a href="GHC.Data.Bag.html#emptyBag"><span class="hs-identifier hs-var">emptyBag</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">10</span></span><span>
</span><span id="line-891"></span><span>
</span><span id="line-892"></span><span class="hs-comment">-- See Note [Constructor size and result discount]</span><span>
</span><span id="line-893"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int -&gt; Bag (Id, Int) -&gt; Int -&gt; ExprSize
</span><a href="GHC.Core.Unfold.html#SizeIs"><span class="hs-identifier hs-var">SizeIs</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">10</span></span><span> </span><span class="annot"><span class="annottext">Bag (Id, Int)
forall a. Bag a
</span><a href="GHC.Data.Bag.html#emptyBag"><span class="hs-identifier hs-var">emptyBag</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">10</span></span><span>
</span><span id="line-894"></span><span>
</span><span id="line-895"></span><span class="hs-comment">{- Note [Constructor size and result discount]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Treat a constructors application as size 10, regardless of how many
arguments it has; we are keen to expose them (and we charge separately
for their args).  We can't treat them as size zero, else we find that
(Just x) has size 0, which is the same as a lone variable; and hence
'v' will always be replaced by (Just x), where v is bound to Just x.

The &quot;result discount&quot; is applied if the result of the call is
scrutinised (say by a case).  For a constructor application that will
mean the constructor application will disappear, so we don't need to
charge it to the function.  So the discount should at least match the
cost of the constructor application, namely 10.

Historical note 1: Until Jun 2020 we gave it a &quot;bit of extra
incentive&quot; via a discount of 10*(1 + n_val_args), but that was FAR too
much (#18282).  In particular, consider a huge case tree like

   let r = case y1 of
          Nothing -&gt; B1 a b c
          Just v1 -&gt; case y2 of
                      Nothing -&gt; B1 c b a
                      Just v2 -&gt; ...

If conSize gives a cost of 10 (regardless of n_val_args) and a
discount of 10, that'll make each alternative RHS cost zero.  We
charge 10 for each case alternative (see size_up_alt).  If we give a
bigger discount (say 20) in conSize, we'll make the case expression
cost *nothing*, and that can make a huge case tree cost nothing. This
leads to massive, sometimes exponenial inlinings (#18282).  In short,
don't give a discount that give a negative size to a sub-expression!

Historical note 2: Much longer ago, Simon M tried a MUCH bigger
discount: (10 * (10 + n_val_args)), and said it was an &quot;unambiguous
win&quot;, but its terribly dangerous because a function with many many
case branches, each finishing with a constructor, can have an
arbitrarily large discount.  This led to terrible code bloat: see
#6099.

Note [Unboxed tuple size and result discount]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
However, unboxed tuples count as size zero. I found occasions where we had
        f x y z = case op# x y z of { s -&gt; (# s, () #) }
and f wasn't getting inlined.

I tried giving unboxed tuples a *result discount* of zero (see the
commented-out line).  Why?  When returned as a result they do not
allocate, so maybe we don't want to charge so much for them. If you
have a non-zero discount here, we find that workers often get inlined
back into wrappers, because it look like
    f x = case $wf x of (# a,b #) -&gt; (a,b)
and we are keener because of the case.  However while this change
shrank binary sizes by 0.5% it also made spectral/boyer allocate 5%
more. All other changes were very small. So it's not a big deal but I
didn't adopt the idea.

When fixing #18282 (see Note [Constructor size and result discount])
I changed the result discount to be just 10, not 10*(1+n_val_args).

Note [Function and non-function discounts]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
We want a discount if the function is applied. A good example is
monadic combinators with continuation arguments, where inlining is
quite important.

But we don't want a big discount when a function is called many times
(see the detailed comments with #6048) because if the function is
big it won't be inlined at its many call sites and no benefit results.
Indeed, we can get exponentially big inlinings this way; that is what
#6048 is about.

On the other hand, for data-valued arguments, if there are lots of
case expressions in the body, each one will get smaller if we apply
the function to a constructor application, so we *want* a big discount
if the argument is scrutinised by many case expressions.

Conclusion:
  - For functions, take the max of the discounts
  - For data values, take the sum of the discounts


Note [Literal integer size]
~~~~~~~~~~~~~~~~~~~~~~~~~~~
Literal integers *can* be big (mkInteger [...coefficients...]), but
need not be (IS n).  We just use an arbitrary big-ish constant here
so that, in particular, we don't inline top-level defns like
   n = IS 5
There's no point in doing so -- any optimisations will see the IS
through n's unfolding.  Nor will a big size inhibit unfoldings functions
that mention a literal Integer, because the float-out pass will float
all those constants to top level.
-}</span><span>
</span><span id="line-987"></span><span>
</span><span id="line-988"></span><span class="annot"><a href="GHC.Core.Unfold.html#primOpSize"><span class="hs-identifier hs-type">primOpSize</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Builtin.PrimOps.html#PrimOp"><span class="hs-identifier hs-type">PrimOp</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Int</span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.Unfold.html#ExprSize"><span class="hs-identifier hs-type">ExprSize</span></a></span><span>
</span><span id="line-989"></span><span id="primOpSize"><span class="annot"><span class="annottext">primOpSize :: PrimOp -&gt; Int -&gt; ExprSize
</span><a href="GHC.Core.Unfold.html#primOpSize"><span class="hs-identifier hs-var hs-var">primOpSize</span></a></span></span><span> </span><span id="local-6989586621680863561"><span class="annot"><span class="annottext">PrimOp
</span><a href="#local-6989586621680863561"><span class="hs-identifier hs-var">op</span></a></span></span><span> </span><span id="local-6989586621680863560"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863560"><span class="hs-identifier hs-var">n_val_args</span></a></span></span><span>
</span><span id="line-990"></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">if</span><span> </span><span class="annot"><span class="annottext">PrimOp -&gt; Bool
</span><a href="GHC.Builtin.PrimOps.html#primOpOutOfLine"><span class="hs-identifier hs-var">primOpOutOfLine</span></a></span><span> </span><span class="annot"><span class="annottext">PrimOp
</span><a href="#local-6989586621680863561"><span class="hs-identifier hs-var">op</span></a></span><span>
</span><span id="line-991"></span><span>      </span><span class="hs-keyword">then</span><span> </span><span class="annot"><span class="annottext">Int -&gt; ExprSize
</span><a href="GHC.Core.Unfold.html#sizeN"><span class="hs-identifier hs-var">sizeN</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863559"><span class="hs-identifier hs-var">op_size</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="../../base/src/GHC.Num.html#%2B"><span class="hs-operator hs-var">+</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863560"><span class="hs-identifier hs-var">n_val_args</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-992"></span><span>      </span><span class="hs-keyword">else</span><span> </span><span class="annot"><span class="annottext">Int -&gt; ExprSize
</span><a href="GHC.Core.Unfold.html#sizeN"><span class="hs-identifier hs-var">sizeN</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863559"><span class="hs-identifier hs-var">op_size</span></a></span><span>
</span><span id="line-993"></span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-994"></span><span>   </span><span id="local-6989586621680863559"><span class="annot"><span class="annottext">op_size :: Int
</span><a href="#local-6989586621680863559"><span class="hs-identifier hs-var hs-var">op_size</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">PrimOp -&gt; Int
</span><a href="GHC.Builtin.PrimOps.html#primOpCodeSize"><span class="hs-identifier hs-var">primOpCodeSize</span></a></span><span> </span><span class="annot"><span class="annottext">PrimOp
</span><a href="#local-6989586621680863561"><span class="hs-identifier hs-var">op</span></a></span><span>
</span><span id="line-995"></span><span>
</span><span id="line-996"></span><span>
</span><span id="line-997"></span><span class="annot"><a href="GHC.Core.Unfold.html#buildSize"><span class="hs-identifier hs-type">buildSize</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.Unfold.html#ExprSize"><span class="hs-identifier hs-type">ExprSize</span></a></span><span>
</span><span id="line-998"></span><span id="buildSize"><span class="annot"><span class="annottext">buildSize :: ExprSize
</span><a href="GHC.Core.Unfold.html#buildSize"><span class="hs-identifier hs-var hs-var">buildSize</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int -&gt; Bag (Id, Int) -&gt; Int -&gt; ExprSize
</span><a href="GHC.Core.Unfold.html#SizeIs"><span class="hs-identifier hs-var">SizeIs</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">0</span></span><span> </span><span class="annot"><span class="annottext">Bag (Id, Int)
forall a. Bag a
</span><a href="GHC.Data.Bag.html#emptyBag"><span class="hs-identifier hs-var">emptyBag</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">40</span></span><span>
</span><span id="line-999"></span><span>        </span><span class="hs-comment">-- We really want to inline applications of build</span><span>
</span><span id="line-1000"></span><span>        </span><span class="hs-comment">-- build t (\cn -&gt; e) should cost only the cost of e (because build will be inlined later)</span><span>
</span><span id="line-1001"></span><span>        </span><span class="hs-comment">-- Indeed, we should add a result_discount because build is</span><span>
</span><span id="line-1002"></span><span>        </span><span class="hs-comment">-- very like a constructor.  We don't bother to check that the</span><span>
</span><span id="line-1003"></span><span>        </span><span class="hs-comment">-- build is saturated (it usually is).  The &quot;-2&quot; discounts for the \c n,</span><span>
</span><span id="line-1004"></span><span>        </span><span class="hs-comment">-- The &quot;4&quot; is rather arbitrary.</span><span>
</span><span id="line-1005"></span><span>
</span><span id="line-1006"></span><span class="annot"><a href="GHC.Core.Unfold.html#augmentSize"><span class="hs-identifier hs-type">augmentSize</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.Unfold.html#ExprSize"><span class="hs-identifier hs-type">ExprSize</span></a></span><span>
</span><span id="line-1007"></span><span id="augmentSize"><span class="annot"><span class="annottext">augmentSize :: ExprSize
</span><a href="GHC.Core.Unfold.html#augmentSize"><span class="hs-identifier hs-var hs-var">augmentSize</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int -&gt; Bag (Id, Int) -&gt; Int -&gt; ExprSize
</span><a href="GHC.Core.Unfold.html#SizeIs"><span class="hs-identifier hs-var">SizeIs</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">0</span></span><span> </span><span class="annot"><span class="annottext">Bag (Id, Int)
forall a. Bag a
</span><a href="GHC.Data.Bag.html#emptyBag"><span class="hs-identifier hs-var">emptyBag</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">40</span></span><span>
</span><span id="line-1008"></span><span>        </span><span class="hs-comment">-- Ditto (augment t (\cn -&gt; e) ys) should cost only the cost of</span><span>
</span><span id="line-1009"></span><span>        </span><span class="hs-comment">-- e plus ys. The -2 accounts for the \cn</span><span>
</span><span id="line-1010"></span><span>
</span><span id="line-1011"></span><span class="hs-comment">-- When we return a lambda, give a discount if it's used (applied)</span><span>
</span><span id="line-1012"></span><span class="annot"><a href="GHC.Core.Unfold.html#lamScrutDiscount"><span class="hs-identifier hs-type">lamScrutDiscount</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Driver.Session.html#DynFlags"><span class="hs-identifier hs-type">DynFlags</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.Unfold.html#ExprSize"><span class="hs-identifier hs-type">ExprSize</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.Unfold.html#ExprSize"><span class="hs-identifier hs-type">ExprSize</span></a></span><span>
</span><span id="line-1013"></span><span id="lamScrutDiscount"><span class="annot"><span class="annottext">lamScrutDiscount :: DynFlags -&gt; ExprSize -&gt; ExprSize
</span><a href="GHC.Core.Unfold.html#lamScrutDiscount"><span class="hs-identifier hs-var hs-var">lamScrutDiscount</span></a></span></span><span> </span><span id="local-6989586621680863557"><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680863557"><span class="hs-identifier hs-var">dflags</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.Unfold.html#SizeIs"><span class="hs-identifier hs-type">SizeIs</span></a></span><span> </span><span id="local-6989586621680863556"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863556"><span class="hs-identifier hs-var">n</span></a></span></span><span> </span><span id="local-6989586621680863555"><span class="annot"><span class="annottext">Bag (Id, Int)
</span><a href="#local-6989586621680863555"><span class="hs-identifier hs-var">vs</span></a></span></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-identifier">_</span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int -&gt; Bag (Id, Int) -&gt; Int -&gt; ExprSize
</span><a href="GHC.Core.Unfold.html#SizeIs"><span class="hs-identifier hs-var">SizeIs</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863556"><span class="hs-identifier hs-var">n</span></a></span><span> </span><span class="annot"><span class="annottext">Bag (Id, Int)
</span><a href="#local-6989586621680863555"><span class="hs-identifier hs-var">vs</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">DynFlags -&gt; Int
</span><a href="GHC.Driver.Session.html#ufFunAppDiscount"><span class="hs-identifier hs-var hs-var">ufFunAppDiscount</span></a></span><span> </span><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680863557"><span class="hs-identifier hs-var">dflags</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1014"></span><span class="annot"><a href="GHC.Core.Unfold.html#lamScrutDiscount"><span class="hs-identifier hs-var">lamScrutDiscount</span></a></span><span> </span><span class="annot"><span class="annottext">DynFlags
</span><span class="hs-identifier">_</span></span><span>      </span><span class="annot"><span class="annottext">ExprSize
</span><a href="GHC.Core.Unfold.html#TooBig"><span class="hs-identifier hs-var">TooBig</span></a></span><span>          </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">ExprSize
</span><a href="GHC.Core.Unfold.html#TooBig"><span class="hs-identifier hs-var">TooBig</span></a></span><span>
</span><span id="line-1015"></span><span>
</span><span id="line-1016"></span><span class="hs-comment">{-
Note [addAltSize result discounts]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
When adding the size of alternatives, we *add* the result discounts
too, rather than take the *maximum*.  For a multi-branch case, this
gives a discount for each branch that returns a constructor, making us
keener to inline.  I did try using 'max' instead, but it makes nofib
'rewrite' and 'puzzle' allocate significantly more, and didn't make
binary sizes shrink significantly either.

Note [Discounts and thresholds]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Constants for discounts and thesholds are defined in &quot;GHC.Driver.Session&quot;,
all of form ufXxxx.   They are:

ufCreationThreshold
     At a definition site, if the unfolding is bigger than this, we
     may discard it altogether

ufUseThreshold
     At a call site, if the unfolding, less discounts, is smaller than
     this, then it's small enough inline

ufDictDiscount
     The discount for each occurrence of a dictionary argument
     as an argument of a class method.  Should be pretty small
     else big functions may get inlined

ufFunAppDiscount
     Discount for a function argument that is applied.  Quite
     large, because if we inline we avoid the higher-order call.

ufDearOp
     The size of a foreign call or not-dupable PrimOp

ufVeryAggressive
     If True, the compiler ignores all the thresholds and inlines very
     aggressively. It still adheres to arity, simplifier phase control and
     loop breakers.


Historical Note: Before April 2020 we had another factor,
ufKeenessFactor, which would scale the discounts before they were subtracted
from the size. This was justified with the following comment:

  -- We multiply the raw discounts (args_discount and result_discount)
  -- ty opt_UnfoldingKeenessFactor because the former have to do with
  --  *size* whereas the discounts imply that there's some extra
  --  *efficiency* to be gained (e.g. beta reductions, case reductions)
  -- by inlining.

However, this is highly suspect since it means that we subtract a *scaled* size
from an absolute size, resulting in crazy (e.g. negative) scores in some cases
(#15304). We consequently killed off ufKeenessFactor and bumped up the
ufUseThreshold to compensate.


Note [Function applications]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In a function application (f a b)

  - If 'f' is an argument to the function being analysed,
    and there's at least one value arg, record a FunAppDiscount for f

  - If the application if a PAP (arity &gt; 2 in this example)
    record a *result* discount (because inlining
    with &quot;extra&quot; args in the call may mean that we now
    get a saturated application)

Code for manipulating sizes
-}</span><span>
</span><span id="line-1087"></span><span>
</span><span id="line-1088"></span><span class="hs-comment">-- | The size of a candidate expression for unfolding</span><span>
</span><span id="line-1089"></span><span class="hs-keyword">data</span><span> </span><span id="ExprSize"><span class="annot"><a href="GHC.Core.Unfold.html#ExprSize"><span class="hs-identifier hs-var">ExprSize</span></a></span></span><span>
</span><span id="line-1090"></span><span>    </span><span class="hs-glyph">=</span><span> </span><span id="TooBig"><span class="annot"><a href="GHC.Core.Unfold.html#TooBig"><span class="hs-identifier hs-var">TooBig</span></a></span></span><span>
</span><span id="line-1091"></span><span>    </span><span class="hs-glyph">|</span><span> </span><span id="SizeIs"><span class="annot"><a href="GHC.Core.Unfold.html#SizeIs"><span class="hs-identifier hs-var">SizeIs</span></a></span></span><span> </span><span class="hs-special">{</span><span> </span><span id="_es_size_is"><span class="annot"><span class="annottext">ExprSize -&gt; Int
</span><a href="GHC.Core.Unfold.html#_es_size_is"><span class="hs-identifier hs-var hs-var">_es_size_is</span></a></span></span><span>  </span><span class="hs-glyph">::</span><span> </span><span class="hs-pragma">{-# UNPACK</span><span> </span><span class="hs-pragma">#-}</span><span> </span><span class="hs-glyph">!</span><span class="annot"><span class="hs-identifier hs-type">Int</span></span><span> </span><span class="hs-comment">-- ^ Size found</span><span>
</span><span id="line-1092"></span><span>             </span><span class="hs-special">,</span><span> </span><span id="_es_args"><span class="annot"><span class="annottext">ExprSize -&gt; Bag (Id, Int)
</span><a href="GHC.Core.Unfold.html#_es_args"><span class="hs-identifier hs-var hs-var">_es_args</span></a></span></span><span>     </span><span class="hs-glyph">::</span><span> </span><span class="hs-glyph">!</span><span class="hs-special">(</span><span class="annot"><a href="GHC.Data.Bag.html#Bag"><span class="hs-identifier hs-type">Bag</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Types.Var.html#Id"><span class="hs-identifier hs-type">Id</span></a></span><span class="hs-special">,</span><span class="annot"><span class="hs-identifier hs-type">Int</span></span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-1093"></span><span>               </span><span class="hs-comment">-- ^ Arguments cased herein, and discount for each such</span><span>
</span><span id="line-1094"></span><span>             </span><span class="hs-special">,</span><span> </span><span id="_es_discount"><span class="annot"><span class="annottext">ExprSize -&gt; Int
</span><a href="GHC.Core.Unfold.html#_es_discount"><span class="hs-identifier hs-var hs-var">_es_discount</span></a></span></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-pragma">{-# UNPACK</span><span> </span><span class="hs-pragma">#-}</span><span> </span><span class="hs-glyph">!</span><span class="annot"><span class="hs-identifier hs-type">Int</span></span><span>
</span><span id="line-1095"></span><span>               </span><span class="hs-comment">-- ^ Size to subtract if result is scrutinised by a case</span><span>
</span><span id="line-1096"></span><span>               </span><span class="hs-comment">-- expression</span><span>
</span><span id="line-1097"></span><span>             </span><span class="hs-special">}</span><span>
</span><span id="line-1098"></span><span>
</span><span id="line-1099"></span><span class="hs-keyword">instance</span><span> </span><span id="local-6989586621680863549"><span class="annot"><a href="GHC.Utils.Outputable.html#Outputable"><span class="hs-identifier hs-type">Outputable</span></a></span><span> </span><span class="annot"><a href="GHC.Core.Unfold.html#ExprSize"><span class="hs-identifier hs-type">ExprSize</span></a></span></span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-1100"></span><span>  </span><span id="local-6989586621680863547"><span class="annot"><span class="annottext">ppr :: ExprSize -&gt; SDoc
</span><a href="#local-6989586621680863547"><span class="hs-identifier hs-var hs-var hs-var hs-var">ppr</span></a></span></span><span> </span><span class="annot"><span class="annottext">ExprSize
</span><a href="GHC.Core.Unfold.html#TooBig"><span class="hs-identifier hs-var">TooBig</span></a></span><span>         </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;TooBig&quot;</span></span><span>
</span><span id="line-1101"></span><span>  </span><span class="annot"><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.Unfold.html#SizeIs"><span class="hs-identifier hs-type">SizeIs</span></a></span><span> </span><span id="local-6989586621680863545"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863545"><span class="hs-identifier hs-var">a</span></a></span></span><span> </span><span class="annot"><span class="annottext">Bag (Id, Int)
</span><span class="hs-identifier">_</span></span><span> </span><span id="local-6989586621680863544"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863544"><span class="hs-identifier hs-var">c</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#brackets"><span class="hs-identifier hs-var">brackets</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#int"><span class="hs-identifier hs-var">int</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863545"><span class="hs-identifier hs-var">a</span></a></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#int"><span class="hs-identifier hs-var">int</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863544"><span class="hs-identifier hs-var">c</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1102"></span><span>
</span><span id="line-1103"></span><span class="hs-comment">-- subtract the discount before deciding whether to bale out. eg. we</span><span>
</span><span id="line-1104"></span><span class="hs-comment">-- want to inline a large constructor application into a selector:</span><span>
</span><span id="line-1105"></span><span class="hs-comment">--      tup = (a_1, ..., a_99)</span><span>
</span><span id="line-1106"></span><span class="hs-comment">--      x = case tup of ...</span><span>
</span><span id="line-1107"></span><span class="hs-comment">--</span><span>
</span><span id="line-1108"></span><span class="annot"><a href="GHC.Core.Unfold.html#mkSizeIs"><span class="hs-identifier hs-type">mkSizeIs</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Int</span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Int</span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Data.Bag.html#Bag"><span class="hs-identifier hs-type">Bag</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Types.Var.html#Id"><span class="hs-identifier hs-type">Id</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Int</span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Int</span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.Unfold.html#ExprSize"><span class="hs-identifier hs-type">ExprSize</span></a></span><span>
</span><span id="line-1109"></span><span id="mkSizeIs"><span class="annot"><span class="annottext">mkSizeIs :: Int -&gt; Int -&gt; Bag (Id, Int) -&gt; Int -&gt; ExprSize
</span><a href="GHC.Core.Unfold.html#mkSizeIs"><span class="hs-identifier hs-var hs-var">mkSizeIs</span></a></span></span><span> </span><span id="local-6989586621680863540"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863540"><span class="hs-identifier hs-var">max</span></a></span></span><span> </span><span id="local-6989586621680863539"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863539"><span class="hs-identifier hs-var">n</span></a></span></span><span> </span><span id="local-6989586621680863538"><span class="annot"><span class="annottext">Bag (Id, Int)
</span><a href="#local-6989586621680863538"><span class="hs-identifier hs-var">xs</span></a></span></span><span> </span><span id="local-6989586621680863537"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863537"><span class="hs-identifier hs-var">d</span></a></span></span><span> </span><span class="hs-glyph">|</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863539"><span class="hs-identifier hs-var">n</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="../../base/src/GHC.Num.html#-"><span class="hs-glyph hs-var">-</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863537"><span class="hs-identifier hs-var">d</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Bool
forall a. Ord a =&gt; a -&gt; a -&gt; Bool
</span><span class="hs-operator hs-var">&gt;</span></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863540"><span class="hs-identifier hs-var">max</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">ExprSize
</span><a href="GHC.Core.Unfold.html#TooBig"><span class="hs-identifier hs-var">TooBig</span></a></span><span>
</span><span id="line-1110"></span><span>                    </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span>     </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int -&gt; Bag (Id, Int) -&gt; Int -&gt; ExprSize
</span><a href="GHC.Core.Unfold.html#SizeIs"><span class="hs-identifier hs-var">SizeIs</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863539"><span class="hs-identifier hs-var">n</span></a></span><span> </span><span class="annot"><span class="annottext">Bag (Id, Int)
</span><a href="#local-6989586621680863538"><span class="hs-identifier hs-var">xs</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863537"><span class="hs-identifier hs-var">d</span></a></span><span>
</span><span id="line-1111"></span><span>
</span><span id="line-1112"></span><span class="annot"><a href="GHC.Core.Unfold.html#maxSize"><span class="hs-identifier hs-type">maxSize</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.Unfold.html#ExprSize"><span class="hs-identifier hs-type">ExprSize</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.Unfold.html#ExprSize"><span class="hs-identifier hs-type">ExprSize</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.Unfold.html#ExprSize"><span class="hs-identifier hs-type">ExprSize</span></a></span><span>
</span><span id="line-1113"></span><span id="maxSize"><span class="annot"><span class="annottext">maxSize :: ExprSize -&gt; ExprSize -&gt; ExprSize
</span><a href="GHC.Core.Unfold.html#maxSize"><span class="hs-identifier hs-var hs-var">maxSize</span></a></span></span><span> </span><span class="annot"><span class="annottext">ExprSize
</span><a href="GHC.Core.Unfold.html#TooBig"><span class="hs-identifier hs-var">TooBig</span></a></span><span>         </span><span class="annot"><span class="annottext">ExprSize
</span><span class="hs-identifier">_</span></span><span>                                  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">ExprSize
</span><a href="GHC.Core.Unfold.html#TooBig"><span class="hs-identifier hs-var">TooBig</span></a></span><span>
</span><span id="line-1114"></span><span class="annot"><a href="GHC.Core.Unfold.html#maxSize"><span class="hs-identifier hs-var">maxSize</span></a></span><span> </span><span class="annot"><span class="annottext">ExprSize
</span><span class="hs-identifier">_</span></span><span>              </span><span class="annot"><span class="annottext">ExprSize
</span><a href="GHC.Core.Unfold.html#TooBig"><span class="hs-identifier hs-var">TooBig</span></a></span><span>                             </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">ExprSize
</span><a href="GHC.Core.Unfold.html#TooBig"><span class="hs-identifier hs-var">TooBig</span></a></span><span>
</span><span id="line-1115"></span><span class="annot"><a href="GHC.Core.Unfold.html#maxSize"><span class="hs-identifier hs-var">maxSize</span></a></span><span> </span><span id="local-6989586621680863536"><span class="annot"><span class="annottext">s1 :: ExprSize
</span><a href="#local-6989586621680863536"><span class="hs-identifier hs-var">s1</span></a></span></span><span class="hs-glyph">@</span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.Unfold.html#SizeIs"><span class="hs-identifier hs-type">SizeIs</span></a></span><span> </span><span id="local-6989586621680863535"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863535"><span class="hs-identifier hs-var">n1</span></a></span></span><span> </span><span class="annot"><span class="annottext">Bag (Id, Int)
</span><span class="hs-identifier">_</span></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-identifier">_</span></span><span class="hs-special">)</span><span> </span><span id="local-6989586621680863534"><span class="annot"><span class="annottext">s2 :: ExprSize
</span><a href="#local-6989586621680863534"><span class="hs-identifier hs-var">s2</span></a></span></span><span class="hs-glyph">@</span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.Unfold.html#SizeIs"><span class="hs-identifier hs-type">SizeIs</span></a></span><span> </span><span id="local-6989586621680863533"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863533"><span class="hs-identifier hs-var">n2</span></a></span></span><span> </span><span class="annot"><span class="annottext">Bag (Id, Int)
</span><span class="hs-identifier">_</span></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-identifier">_</span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863535"><span class="hs-identifier hs-var">n1</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Bool
forall a. Ord a =&gt; a -&gt; a -&gt; Bool
</span><span class="hs-operator hs-var">&gt;</span></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863533"><span class="hs-identifier hs-var">n2</span></a></span><span>   </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">ExprSize
</span><a href="#local-6989586621680863536"><span class="hs-identifier hs-var">s1</span></a></span><span>
</span><span id="line-1116"></span><span>                                              </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">ExprSize
</span><a href="#local-6989586621680863534"><span class="hs-identifier hs-var">s2</span></a></span><span>
</span><span id="line-1117"></span><span>
</span><span id="line-1118"></span><span class="annot"><a href="GHC.Core.Unfold.html#sizeZero"><span class="hs-identifier hs-type">sizeZero</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.Unfold.html#ExprSize"><span class="hs-identifier hs-type">ExprSize</span></a></span><span>
</span><span id="line-1119"></span><span class="annot"><a href="GHC.Core.Unfold.html#sizeN"><span class="hs-identifier hs-type">sizeN</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Int</span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.Unfold.html#ExprSize"><span class="hs-identifier hs-type">ExprSize</span></a></span><span>
</span><span id="line-1120"></span><span>
</span><span id="line-1121"></span><span id="sizeZero"><span class="annot"><span class="annottext">sizeZero :: ExprSize
</span><a href="GHC.Core.Unfold.html#sizeZero"><span class="hs-identifier hs-var hs-var">sizeZero</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int -&gt; Bag (Id, Int) -&gt; Int -&gt; ExprSize
</span><a href="GHC.Core.Unfold.html#SizeIs"><span class="hs-identifier hs-var">SizeIs</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">0</span></span><span> </span><span class="annot"><span class="annottext">Bag (Id, Int)
forall a. Bag a
</span><a href="GHC.Data.Bag.html#emptyBag"><span class="hs-identifier hs-var">emptyBag</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">0</span></span><span>
</span><span id="line-1122"></span><span id="sizeN"><span class="annot"><span class="annottext">sizeN :: Int -&gt; ExprSize
</span><a href="GHC.Core.Unfold.html#sizeN"><span class="hs-identifier hs-var hs-var">sizeN</span></a></span></span><span> </span><span id="local-6989586621680863532"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863532"><span class="hs-identifier hs-var">n</span></a></span></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int -&gt; Bag (Id, Int) -&gt; Int -&gt; ExprSize
</span><a href="GHC.Core.Unfold.html#SizeIs"><span class="hs-identifier hs-var">SizeIs</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863532"><span class="hs-identifier hs-var">n</span></a></span><span> </span><span class="annot"><span class="annottext">Bag (Id, Int)
forall a. Bag a
</span><a href="GHC.Data.Bag.html#emptyBag"><span class="hs-identifier hs-var">emptyBag</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">0</span></span><span>
</span><span id="line-1123"></span><span>
</span><span id="line-1124"></span><span class="hs-comment">{-
************************************************************************
*                                                                      *
\subsection[considerUnfolding]{Given all the info, do (not) do the unfolding}
*                                                                      *
************************************************************************

We use 'couldBeSmallEnoughToInline' to avoid exporting inlinings that
we ``couldn't possibly use'' on the other side.  Can be overridden w/
flaggery.  Just the same as smallEnoughToInline, except that it has no
actual arguments.
-}</span><span>
</span><span id="line-1136"></span><span>
</span><span id="line-1137"></span><span class="annot"><a href="GHC.Core.Unfold.html#couldBeSmallEnoughToInline"><span class="hs-identifier hs-type">couldBeSmallEnoughToInline</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Driver.Session.html#DynFlags"><span class="hs-identifier hs-type">DynFlags</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Int</span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.html#CoreExpr"><span class="hs-identifier hs-type">CoreExpr</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Bool</span></span><span>
</span><span id="line-1138"></span><span id="couldBeSmallEnoughToInline"><span class="annot"><span class="annottext">couldBeSmallEnoughToInline :: DynFlags -&gt; Int -&gt; CoreArg -&gt; Bool
</span><a href="GHC.Core.Unfold.html#couldBeSmallEnoughToInline"><span class="hs-identifier hs-var hs-var">couldBeSmallEnoughToInline</span></a></span></span><span> </span><span id="local-6989586621680863531"><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680863531"><span class="hs-identifier hs-var">dflags</span></a></span></span><span> </span><span id="local-6989586621680863530"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863530"><span class="hs-identifier hs-var">threshold</span></a></span></span><span> </span><span id="local-6989586621680863529"><span class="annot"><span class="annottext">CoreArg
</span><a href="#local-6989586621680863529"><span class="hs-identifier hs-var">rhs</span></a></span></span><span>
</span><span id="line-1139"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">DynFlags -&gt; Int -&gt; [Id] -&gt; CoreArg -&gt; ExprSize
</span><a href="GHC.Core.Unfold.html#sizeExpr"><span class="hs-identifier hs-var">sizeExpr</span></a></span><span> </span><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680863531"><span class="hs-identifier hs-var">dflags</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863530"><span class="hs-identifier hs-var">threshold</span></a></span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span> </span><span class="annot"><span class="annottext">CoreArg
</span><a href="#local-6989586621680863528"><span class="hs-identifier hs-var">body</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-1140"></span><span>       </span><span class="annot"><span class="annottext">ExprSize
</span><a href="GHC.Core.Unfold.html#TooBig"><span class="hs-identifier hs-var">TooBig</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">False</span></span><span>
</span><span id="line-1141"></span><span>       </span><span class="annot"><span class="annottext">ExprSize
</span><span class="hs-identifier">_</span></span><span>      </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">True</span></span><span>
</span><span id="line-1142"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-1143"></span><span>    </span><span class="hs-special">(</span><span class="annot"><span class="annottext">[Id]
</span><span class="hs-identifier">_</span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621680863528"><span class="annot"><span class="annottext">CoreArg
</span><a href="#local-6989586621680863528"><span class="hs-identifier hs-var">body</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">CoreArg -&gt; ([Id], CoreArg)
forall b. Expr b -&gt; ([b], Expr b)
</span><a href="GHC.Core.html#collectBinders"><span class="hs-identifier hs-var">collectBinders</span></a></span><span> </span><span class="annot"><span class="annottext">CoreArg
</span><a href="#local-6989586621680863529"><span class="hs-identifier hs-var">rhs</span></a></span><span>
</span><span id="line-1144"></span><span>
</span><span id="line-1145"></span><span class="hs-comment">----------------</span><span>
</span><span id="line-1146"></span><span class="annot"><a href="GHC.Core.Unfold.html#smallEnoughToInline"><span class="hs-identifier hs-type">smallEnoughToInline</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Driver.Session.html#DynFlags"><span class="hs-identifier hs-type">DynFlags</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.html#Unfolding"><span class="hs-identifier hs-type">Unfolding</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Bool</span></span><span>
</span><span id="line-1147"></span><span id="smallEnoughToInline"><span class="annot"><span class="annottext">smallEnoughToInline :: DynFlags -&gt; Unfolding -&gt; Bool
</span><a href="GHC.Core.Unfold.html#smallEnoughToInline"><span class="hs-identifier hs-var hs-var">smallEnoughToInline</span></a></span></span><span> </span><span id="local-6989586621680863527"><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680863527"><span class="hs-identifier hs-var">dflags</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#CoreUnfolding"><span class="hs-identifier hs-type">CoreUnfolding</span></a></span><span> </span><span class="hs-special">{</span><span class="annot"><span class="annottext">uf_guidance :: Unfolding -&gt; UnfoldingGuidance
</span><a href="GHC.Core.html#uf_guidance"><span class="hs-identifier hs-var">uf_guidance</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><a href="GHC.Core.html#UnfIfGoodArgs"><span class="hs-identifier hs-type">UnfIfGoodArgs</span></a></span><span> </span><span class="hs-special">{</span><span class="annot"><span class="annottext">ug_size :: UnfoldingGuidance -&gt; Int
</span><a href="GHC.Core.html#ug_size"><span class="hs-identifier hs-var">ug_size</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680863526"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863526"><span class="hs-identifier hs-var">size</span></a></span></span><span class="hs-special">}</span><span class="hs-special">}</span><span class="hs-special">)</span><span>
</span><span id="line-1148"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863526"><span class="hs-identifier hs-var">size</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Bool
forall a. Ord a =&gt; a -&gt; a -&gt; Bool
</span><span class="hs-operator hs-var">&lt;=</span></span><span> </span><span class="annot"><span class="annottext">DynFlags -&gt; Int
</span><a href="GHC.Driver.Session.html#ufUseThreshold"><span class="hs-identifier hs-var hs-var">ufUseThreshold</span></a></span><span> </span><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680863527"><span class="hs-identifier hs-var">dflags</span></a></span><span>
</span><span id="line-1149"></span><span class="annot"><a href="GHC.Core.Unfold.html#smallEnoughToInline"><span class="hs-identifier hs-var">smallEnoughToInline</span></a></span><span> </span><span class="annot"><span class="annottext">DynFlags
</span><span class="hs-identifier">_</span></span><span> </span><span class="annot"><span class="annottext">Unfolding
</span><span class="hs-identifier">_</span></span><span>
</span><span id="line-1150"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">False</span></span><span>
</span><span id="line-1151"></span><span>
</span><span id="line-1152"></span><span class="hs-comment">----------------</span><span>
</span><span id="line-1153"></span><span>
</span><span id="line-1154"></span><span class="annot"><a href="GHC.Core.Unfold.html#certainlyWillInline"><span class="hs-identifier hs-type">certainlyWillInline</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Driver.Session.html#DynFlags"><span class="hs-identifier hs-type">DynFlags</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Types.Id.Info.html#IdInfo"><span class="hs-identifier hs-type">IdInfo</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Maybe"><span class="hs-identifier hs-type">Maybe</span></a></span><span> </span><span class="annot"><a href="GHC.Core.html#Unfolding"><span class="hs-identifier hs-type">Unfolding</span></a></span><span>
</span><span id="line-1155"></span><span class="hs-comment">-- ^ Sees if the unfolding is pretty certain to inline.</span><span>
</span><span id="line-1156"></span><span class="hs-comment">-- If so, return a *stable* unfolding for it, that will always inline.</span><span>
</span><span id="line-1157"></span><span id="certainlyWillInline"><span class="annot"><span class="annottext">certainlyWillInline :: DynFlags -&gt; IdInfo -&gt; Maybe Unfolding
</span><a href="GHC.Core.Unfold.html#certainlyWillInline"><span class="hs-identifier hs-var hs-var">certainlyWillInline</span></a></span></span><span> </span><span id="local-6989586621680863524"><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680863524"><span class="hs-identifier hs-var">dflags</span></a></span></span><span> </span><span id="local-6989586621680863523"><span class="annot"><span class="annottext">IdInfo
</span><a href="#local-6989586621680863523"><span class="hs-identifier hs-var">fn_info</span></a></span></span><span>
</span><span id="line-1158"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">IdInfo -&gt; Unfolding
</span><a href="GHC.Types.Id.Info.html#unfoldingInfo"><span class="hs-identifier hs-var hs-var">unfoldingInfo</span></a></span><span> </span><span class="annot"><span class="annottext">IdInfo
</span><a href="#local-6989586621680863523"><span class="hs-identifier hs-var">fn_info</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-1159"></span><span>      </span><span class="annot"><a href="GHC.Core.html#CoreUnfolding"><span class="hs-identifier hs-type">CoreUnfolding</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">uf_tmpl :: Unfolding -&gt; CoreArg
</span><a href="GHC.Core.html#uf_tmpl"><span class="hs-identifier hs-var">uf_tmpl</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680863521"><span class="annot"><span class="annottext">CoreArg
</span><a href="#local-6989586621680863521"><span class="hs-identifier hs-var">e</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">uf_guidance :: Unfolding -&gt; UnfoldingGuidance
</span><a href="GHC.Core.html#uf_guidance"><span class="hs-identifier hs-var">uf_guidance</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680863520"><span class="annot"><span class="annottext">UnfoldingGuidance
</span><a href="#local-6989586621680863520"><span class="hs-identifier hs-var">g</span></a></span></span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-1160"></span><span>        </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621680863519"><span class="hs-identifier hs-var">loop_breaker</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Maybe Unfolding
forall a. Maybe a
</span><a href="../../base/src/GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span>      </span><span class="hs-comment">-- Won't inline, so try w/w</span><span>
</span><span id="line-1161"></span><span>        </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621680863518"><span class="hs-identifier hs-var">noinline</span></a></span><span>     </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Maybe Unfolding
forall a. Maybe a
</span><a href="../../base/src/GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span>      </span><span class="hs-comment">-- See Note [Worker-wrapper for NOINLINE functions]</span><span>
</span><span id="line-1162"></span><span>        </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span>    </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">CoreArg -&gt; UnfoldingGuidance -&gt; Maybe Unfolding
</span><a href="#local-6989586621680863517"><span class="hs-identifier hs-var">do_cunf</span></a></span><span> </span><span class="annot"><span class="annottext">CoreArg
</span><a href="#local-6989586621680863521"><span class="hs-identifier hs-var">e</span></a></span><span> </span><span class="annot"><span class="annottext">UnfoldingGuidance
</span><a href="#local-6989586621680863520"><span class="hs-identifier hs-var">g</span></a></span><span>  </span><span class="hs-comment">-- Depends on size, so look at that</span><span>
</span><span id="line-1163"></span><span>
</span><span id="line-1164"></span><span>      </span><span class="annot"><a href="GHC.Core.html#DFunUnfolding"><span class="hs-identifier hs-type">DFunUnfolding</span></a></span><span> </span><span class="hs-special">{</span><span class="hs-special">}</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Unfolding -&gt; Maybe Unfolding
forall a. a -&gt; Maybe a
</span><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-var">Just</span></a></span><span> </span><span class="annot"><span class="annottext">Unfolding
</span><a href="#local-6989586621680863516"><span class="hs-identifier hs-var">fn_unf</span></a></span><span>  </span><span class="hs-comment">-- Don't w/w DFuns; it never makes sense</span><span>
</span><span id="line-1165"></span><span>                                       </span><span class="hs-comment">-- to do so, and even if it is currently a</span><span>
</span><span id="line-1166"></span><span>                                       </span><span class="hs-comment">-- loop breaker, it may not be later</span><span>
</span><span id="line-1167"></span><span>
</span><span id="line-1168"></span><span>      </span><span id="local-6989586621680863515"><span class="annot"><span class="annottext">Unfolding
</span><a href="#local-6989586621680863515"><span class="hs-identifier hs-var">_other_unf</span></a></span></span><span>       </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Maybe Unfolding
forall a. Maybe a
</span><a href="../../base/src/GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span>
</span><span id="line-1169"></span><span>
</span><span id="line-1170"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-1171"></span><span>    </span><span id="local-6989586621680863519"><span class="annot"><span class="annottext">loop_breaker :: Bool
</span><a href="#local-6989586621680863519"><span class="hs-identifier hs-var hs-var">loop_breaker</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">OccInfo -&gt; Bool
</span><a href="GHC.Types.Basic.html#isStrongLoopBreaker"><span class="hs-identifier hs-var">isStrongLoopBreaker</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">IdInfo -&gt; OccInfo
</span><a href="GHC.Types.Id.Info.html#occInfo"><span class="hs-identifier hs-var hs-var">occInfo</span></a></span><span> </span><span class="annot"><span class="annottext">IdInfo
</span><a href="#local-6989586621680863523"><span class="hs-identifier hs-var">fn_info</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1172"></span><span>    </span><span id="local-6989586621680863518"><span class="annot"><span class="annottext">noinline :: Bool
</span><a href="#local-6989586621680863518"><span class="hs-identifier hs-var hs-var">noinline</span></a></span></span><span>     </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">InlinePragma -&gt; InlineSpec
</span><a href="GHC.Types.Basic.html#inlinePragmaSpec"><span class="hs-identifier hs-var">inlinePragmaSpec</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">IdInfo -&gt; InlinePragma
</span><a href="GHC.Types.Id.Info.html#inlinePragInfo"><span class="hs-identifier hs-var hs-var">inlinePragInfo</span></a></span><span> </span><span class="annot"><span class="annottext">IdInfo
</span><a href="#local-6989586621680863523"><span class="hs-identifier hs-var">fn_info</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">InlineSpec -&gt; InlineSpec -&gt; Bool
forall a. Eq a =&gt; a -&gt; a -&gt; Bool
</span><span class="hs-operator hs-var">==</span></span><span> </span><span class="annot"><span class="annottext">InlineSpec
</span><a href="GHC.Types.Basic.html#NoInline"><span class="hs-identifier hs-var">NoInline</span></a></span><span>
</span><span id="line-1173"></span><span>    </span><span id="local-6989586621680863516"><span class="annot"><span class="annottext">fn_unf :: Unfolding
</span><a href="#local-6989586621680863516"><span class="hs-identifier hs-var hs-var">fn_unf</span></a></span></span><span>       </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">IdInfo -&gt; Unfolding
</span><a href="GHC.Types.Id.Info.html#unfoldingInfo"><span class="hs-identifier hs-var hs-var">unfoldingInfo</span></a></span><span> </span><span class="annot"><span class="annottext">IdInfo
</span><a href="#local-6989586621680863523"><span class="hs-identifier hs-var">fn_info</span></a></span><span>
</span><span id="line-1174"></span><span>
</span><span id="line-1175"></span><span>    </span><span class="annot"><a href="#local-6989586621680863517"><span class="hs-identifier hs-type">do_cunf</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.html#CoreExpr"><span class="hs-identifier hs-type">CoreExpr</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.html#UnfoldingGuidance"><span class="hs-identifier hs-type">UnfoldingGuidance</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Maybe"><span class="hs-identifier hs-type">Maybe</span></a></span><span> </span><span class="annot"><a href="GHC.Core.html#Unfolding"><span class="hs-identifier hs-type">Unfolding</span></a></span><span>
</span><span id="line-1176"></span><span>    </span><span id="local-6989586621680863517"><span class="annot"><span class="annottext">do_cunf :: CoreArg -&gt; UnfoldingGuidance -&gt; Maybe Unfolding
</span><a href="#local-6989586621680863517"><span class="hs-identifier hs-var hs-var">do_cunf</span></a></span></span><span> </span><span class="annot"><span class="annottext">CoreArg
</span><span class="hs-identifier">_</span></span><span> </span><span class="annot"><span class="annottext">UnfoldingGuidance
</span><a href="GHC.Core.html#UnfNever"><span class="hs-identifier hs-var">UnfNever</span></a></span><span>     </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Maybe Unfolding
forall a. Maybe a
</span><a href="../../base/src/GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span>
</span><span id="line-1177"></span><span>    </span><span class="annot"><a href="#local-6989586621680863517"><span class="hs-identifier hs-var">do_cunf</span></a></span><span> </span><span class="annot"><span class="annottext">CoreArg
</span><span class="hs-identifier">_</span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#UnfWhen"><span class="hs-identifier hs-type">UnfWhen</span></a></span><span> </span><span class="hs-special">{</span><span class="hs-special">}</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Unfolding -&gt; Maybe Unfolding
forall a. a -&gt; Maybe a
</span><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-var">Just</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Unfolding
</span><a href="#local-6989586621680863516"><span class="hs-identifier hs-var">fn_unf</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">uf_src :: UnfoldingSource
</span><a href="GHC.Core.html#uf_src"><span class="hs-identifier hs-var">uf_src</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">UnfoldingSource
</span><a href="GHC.Core.html#InlineStable"><span class="hs-identifier hs-var">InlineStable</span></a></span><span> </span><span class="hs-special">}</span><span class="hs-special">)</span><span>
</span><span id="line-1178"></span><span>                             </span><span class="hs-comment">-- INLINE functions have UnfWhen</span><span>
</span><span id="line-1179"></span><span>
</span><span id="line-1180"></span><span>        </span><span class="hs-comment">-- The UnfIfGoodArgs case seems important.  If we w/w small functions</span><span>
</span><span id="line-1181"></span><span>        </span><span class="hs-comment">-- binary sizes go up by 10%!  (This is with SplitObjs.)</span><span>
</span><span id="line-1182"></span><span>        </span><span class="hs-comment">-- I'm not totally sure why.</span><span>
</span><span id="line-1183"></span><span>        </span><span class="hs-comment">-- INLINABLE functions come via this path</span><span>
</span><span id="line-1184"></span><span>        </span><span class="hs-comment">--    See Note [certainlyWillInline: INLINABLE]</span><span>
</span><span id="line-1185"></span><span>    </span><span class="annot"><a href="#local-6989586621680863517"><span class="hs-identifier hs-var">do_cunf</span></a></span><span> </span><span id="local-6989586621680863508"><span class="annot"><span class="annottext">CoreArg
</span><a href="#local-6989586621680863508"><span class="hs-identifier hs-var">expr</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#UnfIfGoodArgs"><span class="hs-identifier hs-type">UnfIfGoodArgs</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">ug_size :: UnfoldingGuidance -&gt; Int
</span><a href="GHC.Core.html#ug_size"><span class="hs-identifier hs-var">ug_size</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680863507"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863507"><span class="hs-identifier hs-var">size</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">ug_args :: UnfoldingGuidance -&gt; [Int]
</span><a href="GHC.Core.html#ug_args"><span class="hs-identifier hs-var">ug_args</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680863506"><span class="annot"><span class="annottext">[Int]
</span><a href="#local-6989586621680863506"><span class="hs-identifier hs-var">args</span></a></span></span><span> </span><span class="hs-special">}</span><span class="hs-special">)</span><span>
</span><span id="line-1186"></span><span>      </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">IdInfo -&gt; Int
</span><a href="GHC.Types.Id.Info.html#arityInfo"><span class="hs-identifier hs-var">arityInfo</span></a></span><span> </span><span class="annot"><span class="annottext">IdInfo
</span><a href="#local-6989586621680863523"><span class="hs-identifier hs-var">fn_info</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Bool
forall a. Ord a =&gt; a -&gt; a -&gt; Bool
</span><span class="hs-operator hs-var">&gt;</span></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">0</span></span><span>  </span><span class="hs-comment">-- See Note [certainlyWillInline: be careful of thunks]</span><span>
</span><span id="line-1187"></span><span>      </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Bool
</span><span class="hs-identifier hs-var">not</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">StrictSig -&gt; Bool
</span><a href="GHC.Types.Demand.html#isDeadEndSig"><span class="hs-identifier hs-var">isDeadEndSig</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">IdInfo -&gt; StrictSig
</span><a href="GHC.Types.Id.Info.html#strictnessInfo"><span class="hs-identifier hs-var hs-var">strictnessInfo</span></a></span><span> </span><span class="annot"><span class="annottext">IdInfo
</span><a href="#local-6989586621680863523"><span class="hs-identifier hs-var">fn_info</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-1188"></span><span>              </span><span class="hs-comment">-- Do not unconditionally inline a bottoming functions even if</span><span>
</span><span id="line-1189"></span><span>              </span><span class="hs-comment">-- it seems smallish. We've carefully lifted it out to top level,</span><span>
</span><span id="line-1190"></span><span>              </span><span class="hs-comment">-- so we don't want to re-inline it.</span><span>
</span><span id="line-1191"></span><span>      </span><span class="hs-special">,</span><span> </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621680863502"><span class="annot"><span class="annottext">unf_arity :: Int
</span><a href="#local-6989586621680863502"><span class="hs-identifier hs-var hs-var">unf_arity</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[Int] -&gt; Int
forall (t :: * -&gt; *) a. Foldable t =&gt; t a -&gt; Int
</span><a href="../../base/src/Data.Foldable.html#length"><span class="hs-identifier hs-var">length</span></a></span><span> </span><span class="annot"><span class="annottext">[Int]
</span><a href="#local-6989586621680863506"><span class="hs-identifier hs-var">args</span></a></span><span>
</span><span id="line-1192"></span><span>      </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863507"><span class="hs-identifier hs-var">size</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="../../base/src/GHC.Num.html#-"><span class="hs-glyph hs-var">-</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">10</span></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="../../base/src/GHC.Num.html#%2A"><span class="hs-operator hs-var">*</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863502"><span class="hs-identifier hs-var">unf_arity</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="../../base/src/GHC.Num.html#%2B"><span class="hs-operator hs-var">+</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">1</span></span><span class="hs-special">)</span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Bool
forall a. Ord a =&gt; a -&gt; a -&gt; Bool
</span><span class="hs-operator hs-var">&lt;=</span></span><span> </span><span class="annot"><span class="annottext">DynFlags -&gt; Int
</span><a href="GHC.Driver.Session.html#ufUseThreshold"><span class="hs-identifier hs-var hs-var">ufUseThreshold</span></a></span><span> </span><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680863524"><span class="hs-identifier hs-var">dflags</span></a></span><span>
</span><span id="line-1193"></span><span>      </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Unfolding -&gt; Maybe Unfolding
forall a. a -&gt; Maybe a
</span><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-var">Just</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Unfolding
</span><a href="#local-6989586621680863516"><span class="hs-identifier hs-var">fn_unf</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">uf_src :: UnfoldingSource
</span><a href="GHC.Core.html#uf_src"><span class="hs-identifier hs-var">uf_src</span></a></span><span>      </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">UnfoldingSource
</span><a href="GHC.Core.html#InlineStable"><span class="hs-identifier hs-var">InlineStable</span></a></span><span>
</span><span id="line-1194"></span><span>                     </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">uf_guidance :: UnfoldingGuidance
</span><a href="GHC.Core.html#uf_guidance"><span class="hs-identifier hs-var">uf_guidance</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">UnfWhen :: Int -&gt; Bool -&gt; Bool -&gt; UnfoldingGuidance
</span><a href="GHC.Core.html#UnfWhen"><span class="hs-identifier hs-type">UnfWhen</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">ug_arity :: Int
</span><a href="GHC.Core.html#ug_arity"><span class="hs-identifier hs-var">ug_arity</span></a></span><span>     </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863502"><span class="hs-identifier hs-var">unf_arity</span></a></span><span>
</span><span id="line-1195"></span><span>                                             </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">ug_unsat_ok :: Bool
</span><a href="GHC.Core.html#ug_unsat_ok"><span class="hs-identifier hs-var">ug_unsat_ok</span></a></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="GHC.Core.html#unSaturatedOk"><span class="hs-identifier hs-var">unSaturatedOk</span></a></span><span>
</span><span id="line-1196"></span><span>                                             </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">ug_boring_ok :: Bool
</span><a href="GHC.Core.html#ug_boring_ok"><span class="hs-identifier hs-var">ug_boring_ok</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">CoreArg -&gt; Bool
</span><a href="GHC.Core.Unfold.html#inlineBoringOk"><span class="hs-identifier hs-var">inlineBoringOk</span></a></span><span> </span><span class="annot"><span class="annottext">CoreArg
</span><a href="#local-6989586621680863508"><span class="hs-identifier hs-var">expr</span></a></span><span> </span><span class="hs-special">}</span><span> </span><span class="hs-special">}</span><span class="hs-special">)</span><span>
</span><span id="line-1197"></span><span>             </span><span class="hs-comment">-- Note the &quot;unsaturatedOk&quot;. A function like  f = \ab. a</span><span>
</span><span id="line-1198"></span><span>             </span><span class="hs-comment">-- will certainly inline, even if partially applied (f e), so we'd</span><span>
</span><span id="line-1199"></span><span>             </span><span class="hs-comment">-- better make sure that the transformed inlining has the same property</span><span>
</span><span id="line-1200"></span><span>      </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span>
</span><span id="line-1201"></span><span>      </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Maybe Unfolding
forall a. Maybe a
</span><a href="../../base/src/GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span>
</span><span id="line-1202"></span><span>
</span><span id="line-1203"></span><span class="hs-comment">{- Note [certainlyWillInline: be careful of thunks]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Don't claim that thunks will certainly inline, because that risks work
duplication.  Even if the work duplication is not great (eg is_cheap
holds), it can make a big difference in an inner loop In #5623 we
found that the WorkWrap phase thought that
       y = case x of F# v -&gt; F# (v +# v)
was certainlyWillInline, so the addition got duplicated.

Note that we check arityInfo instead of the arity of the unfolding to detect
this case. This is so that we don't accidentally fail to inline small partial
applications, like `f = g 42` (where `g` recurses into `f`) where g has arity 2
(say). Here there is no risk of work duplication, and the RHS is tiny, so
certainlyWillInline should return True. But `unf_arity` is zero! However f's
arity, gotten from `arityInfo fn_info`, is 1.

Failing to say that `f` will inline forces W/W to generate a potentially huge
worker for f that will immediately cancel with `g`'s wrapper anyway, causing
unnecessary churn in the Simplifier while arriving at the same result.

Note [certainlyWillInline: INLINABLE]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
certainlyWillInline /must/ return Nothing for a large INLINABLE thing,
even though we have a stable inlining, so that strictness w/w takes
place.  It makes a big difference to efficiency, and the w/w pass knows
how to transfer the INLINABLE info to the worker; see WorkWrap
Note [Worker-wrapper for INLINABLE functions]

************************************************************************
*                                                                      *
\subsection{callSiteInline}
*                                                                      *
************************************************************************

This is the key function.  It decides whether to inline a variable at a call site

callSiteInline is used at call sites, so it is a bit more generous.
It's a very important function that embodies lots of heuristics.
A non-WHNF can be inlined if it doesn't occur inside a lambda,
and occurs exactly once or
    occurs once in each branch of a case and is small

If the thing is in WHNF, there's no danger of duplicating work,
so we can inline if it occurs once, or is small

NOTE: we don't want to inline top-level functions that always diverge.
It just makes the code bigger.  Tt turns out that the convenient way to prevent
them inlining is to give them a NOINLINE pragma, which we do in
StrictAnal.addStrictnessInfoToTopId
-}</span><span>
</span><span id="line-1253"></span><span>
</span><span id="line-1254"></span><span class="annot"><a href="GHC.Core.Unfold.html#callSiteInline"><span class="hs-identifier hs-type">callSiteInline</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Driver.Session.html#DynFlags"><span class="hs-identifier hs-type">DynFlags</span></a></span><span>
</span><span id="line-1255"></span><span>               </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Types.Var.html#Id"><span class="hs-identifier hs-type">Id</span></a></span><span>                    </span><span class="hs-comment">-- The Id</span><span>
</span><span id="line-1256"></span><span>               </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Bool</span></span><span>                  </span><span class="hs-comment">-- True &lt;=&gt; unfolding is active</span><span>
</span><span id="line-1257"></span><span>               </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Bool</span></span><span>                  </span><span class="hs-comment">-- True if there are no arguments at all (incl type args)</span><span>
</span><span id="line-1258"></span><span>               </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.Unfold.html#ArgSummary"><span class="hs-identifier hs-type">ArgSummary</span></a></span><span class="hs-special">]</span><span>          </span><span class="hs-comment">-- One for each value arg; True if it is interesting</span><span>
</span><span id="line-1259"></span><span>               </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.Unfold.html#CallCtxt"><span class="hs-identifier hs-type">CallCtxt</span></a></span><span>              </span><span class="hs-comment">-- True &lt;=&gt; continuation is interesting</span><span>
</span><span id="line-1260"></span><span>               </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Maybe"><span class="hs-identifier hs-type">Maybe</span></a></span><span> </span><span class="annot"><a href="GHC.Core.html#CoreExpr"><span class="hs-identifier hs-type">CoreExpr</span></a></span><span>        </span><span class="hs-comment">-- Unfolding, if any</span><span>
</span><span id="line-1261"></span><span>
</span><span id="line-1262"></span><span class="hs-keyword">data</span><span> </span><span id="ArgSummary"><span class="annot"><a href="GHC.Core.Unfold.html#ArgSummary"><span class="hs-identifier hs-var">ArgSummary</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="TrivArg"><span class="annot"><a href="GHC.Core.Unfold.html#TrivArg"><span class="hs-identifier hs-var">TrivArg</span></a></span></span><span>       </span><span class="hs-comment">-- Nothing interesting</span><span>
</span><span id="line-1263"></span><span>                </span><span class="hs-glyph">|</span><span> </span><span id="NonTrivArg"><span class="annot"><a href="GHC.Core.Unfold.html#NonTrivArg"><span class="hs-identifier hs-var">NonTrivArg</span></a></span></span><span>    </span><span class="hs-comment">-- Arg has structure</span><span>
</span><span id="line-1264"></span><span>                </span><span class="hs-glyph">|</span><span> </span><span id="ValueArg"><span class="annot"><a href="GHC.Core.Unfold.html#ValueArg"><span class="hs-identifier hs-var">ValueArg</span></a></span></span><span>      </span><span class="hs-comment">-- Arg is a con-app or PAP</span><span>
</span><span id="line-1265"></span><span>                                </span><span class="hs-comment">-- ..or con-like. Note [Conlike is interesting]</span><span>
</span><span id="line-1266"></span><span>
</span><span id="line-1267"></span><span class="hs-keyword">instance</span><span> </span><span id="local-6989586621680863496"><span class="annot"><a href="GHC.Utils.Outputable.html#Outputable"><span class="hs-identifier hs-type">Outputable</span></a></span><span> </span><span class="annot"><a href="GHC.Core.Unfold.html#ArgSummary"><span class="hs-identifier hs-type">ArgSummary</span></a></span></span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-1268"></span><span>  </span><span id="local-6989586621680863495"><span class="annot"><span class="annottext">ppr :: ArgSummary -&gt; SDoc
</span><a href="#local-6989586621680863495"><span class="hs-identifier hs-var hs-var hs-var hs-var">ppr</span></a></span></span><span> </span><span class="annot"><span class="annottext">ArgSummary
</span><a href="GHC.Core.Unfold.html#TrivArg"><span class="hs-identifier hs-var">TrivArg</span></a></span><span>    </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;TrivArg&quot;</span></span><span>
</span><span id="line-1269"></span><span>  </span><span class="annot"><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">ArgSummary
</span><a href="GHC.Core.Unfold.html#NonTrivArg"><span class="hs-identifier hs-var">NonTrivArg</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;NonTrivArg&quot;</span></span><span>
</span><span id="line-1270"></span><span>  </span><span class="annot"><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">ArgSummary
</span><a href="GHC.Core.Unfold.html#ValueArg"><span class="hs-identifier hs-var">ValueArg</span></a></span><span>   </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;ValueArg&quot;</span></span><span>
</span><span id="line-1271"></span><span>
</span><span id="line-1272"></span><span class="annot"><a href="GHC.Core.Unfold.html#nonTriv"><span class="hs-identifier hs-type">nonTriv</span></a></span><span> </span><span class="hs-glyph">::</span><span>  </span><span class="annot"><a href="GHC.Core.Unfold.html#ArgSummary"><span class="hs-identifier hs-type">ArgSummary</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Bool</span></span><span>
</span><span id="line-1273"></span><span id="nonTriv"><span class="annot"><span class="annottext">nonTriv :: ArgSummary -&gt; Bool
</span><a href="GHC.Core.Unfold.html#nonTriv"><span class="hs-identifier hs-var hs-var">nonTriv</span></a></span></span><span> </span><span class="annot"><span class="annottext">ArgSummary
</span><a href="GHC.Core.Unfold.html#TrivArg"><span class="hs-identifier hs-var">TrivArg</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">False</span></span><span>
</span><span id="line-1274"></span><span class="annot"><a href="GHC.Core.Unfold.html#nonTriv"><span class="hs-identifier hs-var">nonTriv</span></a></span><span> </span><span class="annot"><span class="annottext">ArgSummary
</span><span class="hs-identifier">_</span></span><span>       </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">True</span></span><span>
</span><span id="line-1275"></span><span>
</span><span id="line-1276"></span><span class="hs-keyword">data</span><span> </span><span id="CallCtxt"><span class="annot"><a href="GHC.Core.Unfold.html#CallCtxt"><span class="hs-identifier hs-var">CallCtxt</span></a></span></span><span>
</span><span id="line-1277"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span id="BoringCtxt"><span class="annot"><a href="GHC.Core.Unfold.html#BoringCtxt"><span class="hs-identifier hs-var">BoringCtxt</span></a></span></span><span>
</span><span id="line-1278"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span id="RhsCtxt"><span class="annot"><a href="GHC.Core.Unfold.html#RhsCtxt"><span class="hs-identifier hs-var">RhsCtxt</span></a></span></span><span>             </span><span class="hs-comment">-- Rhs of a let-binding; see Note [RHS of lets]</span><span>
</span><span id="line-1279"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span id="DiscArgCtxt"><span class="annot"><a href="GHC.Core.Unfold.html#DiscArgCtxt"><span class="hs-identifier hs-var">DiscArgCtxt</span></a></span></span><span>         </span><span class="hs-comment">-- Argument of a function with non-zero arg discount</span><span>
</span><span id="line-1280"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span id="RuleArgCtxt"><span class="annot"><a href="GHC.Core.Unfold.html#RuleArgCtxt"><span class="hs-identifier hs-var">RuleArgCtxt</span></a></span></span><span>         </span><span class="hs-comment">-- We are somewhere in the argument of a function with rules</span><span>
</span><span id="line-1281"></span><span>
</span><span id="line-1282"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span id="ValAppCtxt"><span class="annot"><a href="GHC.Core.Unfold.html#ValAppCtxt"><span class="hs-identifier hs-var">ValAppCtxt</span></a></span></span><span>          </span><span class="hs-comment">-- We're applied to at least one value arg</span><span>
</span><span id="line-1283"></span><span>                        </span><span class="hs-comment">-- This arises when we have ((f x |&gt; co) y)</span><span>
</span><span id="line-1284"></span><span>                        </span><span class="hs-comment">-- Then the (f x) has argument 'x' but in a ValAppCtxt</span><span>
</span><span id="line-1285"></span><span>
</span><span id="line-1286"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span id="CaseCtxt"><span class="annot"><a href="GHC.Core.Unfold.html#CaseCtxt"><span class="hs-identifier hs-var">CaseCtxt</span></a></span></span><span>            </span><span class="hs-comment">-- We're the scrutinee of a case</span><span>
</span><span id="line-1287"></span><span>                        </span><span class="hs-comment">-- that decomposes its scrutinee</span><span>
</span><span id="line-1288"></span><span>
</span><span id="line-1289"></span><span class="hs-keyword">instance</span><span> </span><span id="local-6989586621680863485"><span class="annot"><a href="GHC.Utils.Outputable.html#Outputable"><span class="hs-identifier hs-type">Outputable</span></a></span><span> </span><span class="annot"><a href="GHC.Core.Unfold.html#CallCtxt"><span class="hs-identifier hs-type">CallCtxt</span></a></span></span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-1290"></span><span>  </span><span id="local-6989586621680863484"><span class="annot"><span class="annottext">ppr :: CallCtxt -&gt; SDoc
</span><a href="#local-6989586621680863484"><span class="hs-identifier hs-var hs-var hs-var hs-var">ppr</span></a></span></span><span> </span><span class="annot"><span class="annottext">CallCtxt
</span><a href="GHC.Core.Unfold.html#CaseCtxt"><span class="hs-identifier hs-var">CaseCtxt</span></a></span><span>    </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;CaseCtxt&quot;</span></span><span>
</span><span id="line-1291"></span><span>  </span><span class="annot"><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">CallCtxt
</span><a href="GHC.Core.Unfold.html#ValAppCtxt"><span class="hs-identifier hs-var">ValAppCtxt</span></a></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;ValAppCtxt&quot;</span></span><span>
</span><span id="line-1292"></span><span>  </span><span class="annot"><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">CallCtxt
</span><a href="GHC.Core.Unfold.html#BoringCtxt"><span class="hs-identifier hs-var">BoringCtxt</span></a></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;BoringCtxt&quot;</span></span><span>
</span><span id="line-1293"></span><span>  </span><span class="annot"><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">CallCtxt
</span><a href="GHC.Core.Unfold.html#RhsCtxt"><span class="hs-identifier hs-var">RhsCtxt</span></a></span><span>     </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;RhsCtxt&quot;</span></span><span>
</span><span id="line-1294"></span><span>  </span><span class="annot"><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">CallCtxt
</span><a href="GHC.Core.Unfold.html#DiscArgCtxt"><span class="hs-identifier hs-var">DiscArgCtxt</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;DiscArgCtxt&quot;</span></span><span>
</span><span id="line-1295"></span><span>  </span><span class="annot"><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">CallCtxt
</span><a href="GHC.Core.Unfold.html#RuleArgCtxt"><span class="hs-identifier hs-var">RuleArgCtxt</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;RuleArgCtxt&quot;</span></span><span>
</span><span id="line-1296"></span><span>
</span><span id="line-1297"></span><span id="callSiteInline"><span class="annot"><span class="annottext">callSiteInline :: DynFlags
-&gt; Id -&gt; Bool -&gt; Bool -&gt; [ArgSummary] -&gt; CallCtxt -&gt; Maybe CoreArg
</span><a href="GHC.Core.Unfold.html#callSiteInline"><span class="hs-identifier hs-var hs-var">callSiteInline</span></a></span></span><span> </span><span id="local-6989586621680863483"><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680863483"><span class="hs-identifier hs-var">dflags</span></a></span></span><span> </span><span id="local-6989586621680863482"><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680863482"><span class="hs-identifier hs-var">id</span></a></span></span><span> </span><span id="local-6989586621680863481"><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621680863481"><span class="hs-identifier hs-var">active_unfolding</span></a></span></span><span> </span><span id="local-6989586621680863480"><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621680863480"><span class="hs-identifier hs-var">lone_variable</span></a></span></span><span> </span><span id="local-6989586621680863479"><span class="annot"><span class="annottext">[ArgSummary]
</span><a href="#local-6989586621680863479"><span class="hs-identifier hs-var">arg_infos</span></a></span></span><span> </span><span id="local-6989586621680863478"><span class="annot"><span class="annottext">CallCtxt
</span><a href="#local-6989586621680863478"><span class="hs-identifier hs-var">cont_info</span></a></span></span><span>
</span><span id="line-1298"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">Id -&gt; Unfolding
</span><a href="GHC.Types.Id.html#idUnfolding"><span class="hs-identifier hs-var">idUnfolding</span></a></span><span> </span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680863482"><span class="hs-identifier hs-var">id</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-1299"></span><span>      </span><span class="hs-comment">-- idUnfolding checks for loop-breakers, returning NoUnfolding</span><span>
</span><span id="line-1300"></span><span>      </span><span class="hs-comment">-- Things with an INLINE pragma may have an unfolding *and*</span><span>
</span><span id="line-1301"></span><span>      </span><span class="hs-comment">-- be a loop breaker  (maybe the knot is not yet untied)</span><span>
</span><span id="line-1302"></span><span>        </span><span class="annot"><a href="GHC.Core.html#CoreUnfolding"><span class="hs-identifier hs-type">CoreUnfolding</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">uf_tmpl :: Unfolding -&gt; CoreArg
</span><a href="GHC.Core.html#uf_tmpl"><span class="hs-identifier hs-var">uf_tmpl</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680863476"><span class="annot"><span class="annottext">CoreArg
</span><a href="#local-6989586621680863476"><span class="hs-identifier hs-var">unf_template</span></a></span></span><span>
</span><span id="line-1303"></span><span>                      </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">uf_is_work_free :: Unfolding -&gt; Bool
</span><a href="GHC.Core.html#uf_is_work_free"><span class="hs-identifier hs-var">uf_is_work_free</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680863475"><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621680863475"><span class="hs-identifier hs-var">is_wf</span></a></span></span><span>
</span><span id="line-1304"></span><span>                      </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">uf_guidance :: Unfolding -&gt; UnfoldingGuidance
</span><a href="GHC.Core.html#uf_guidance"><span class="hs-identifier hs-var">uf_guidance</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680863474"><span class="annot"><span class="annottext">UnfoldingGuidance
</span><a href="#local-6989586621680863474"><span class="hs-identifier hs-var">guidance</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">uf_expandable :: Unfolding -&gt; Bool
</span><a href="GHC.Core.html#uf_expandable"><span class="hs-identifier hs-var">uf_expandable</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680863473"><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621680863473"><span class="hs-identifier hs-var">is_exp</span></a></span></span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-1305"></span><span>          </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621680863481"><span class="hs-identifier hs-var">active_unfolding</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">DynFlags
-&gt; Id
-&gt; Bool
-&gt; [ArgSummary]
-&gt; CallCtxt
-&gt; CoreArg
-&gt; Bool
-&gt; Bool
-&gt; UnfoldingGuidance
-&gt; Maybe CoreArg
</span><a href="GHC.Core.Unfold.html#tryUnfolding"><span class="hs-identifier hs-var">tryUnfolding</span></a></span><span> </span><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680863483"><span class="hs-identifier hs-var">dflags</span></a></span><span> </span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680863482"><span class="hs-identifier hs-var">id</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621680863480"><span class="hs-identifier hs-var">lone_variable</span></a></span><span>
</span><span id="line-1306"></span><span>                                    </span><span class="annot"><span class="annottext">[ArgSummary]
</span><a href="#local-6989586621680863479"><span class="hs-identifier hs-var">arg_infos</span></a></span><span> </span><span class="annot"><span class="annottext">CallCtxt
</span><a href="#local-6989586621680863478"><span class="hs-identifier hs-var">cont_info</span></a></span><span> </span><span class="annot"><span class="annottext">CoreArg
</span><a href="#local-6989586621680863476"><span class="hs-identifier hs-var">unf_template</span></a></span><span>
</span><span id="line-1307"></span><span>                                    </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621680863475"><span class="hs-identifier hs-var">is_wf</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621680863473"><span class="hs-identifier hs-var">is_exp</span></a></span><span> </span><span class="annot"><span class="annottext">UnfoldingGuidance
</span><a href="#local-6989586621680863474"><span class="hs-identifier hs-var">guidance</span></a></span><span>
</span><span id="line-1308"></span><span>          </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">DynFlags -&gt; Id -&gt; String -&gt; SDoc -&gt; Maybe CoreArg -&gt; Maybe CoreArg
forall a. DynFlags -&gt; Id -&gt; String -&gt; SDoc -&gt; a -&gt; a
</span><a href="GHC.Core.Unfold.html#traceInline"><span class="hs-identifier hs-var">traceInline</span></a></span><span> </span><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680863483"><span class="hs-identifier hs-var">dflags</span></a></span><span> </span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680863482"><span class="hs-identifier hs-var">id</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;Inactive unfolding:&quot;</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Id -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680863482"><span class="hs-identifier hs-var">id</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Maybe CoreArg
forall a. Maybe a
</span><a href="../../base/src/GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span>
</span><span id="line-1309"></span><span>        </span><span class="annot"><span class="annottext">Unfolding
</span><a href="GHC.Core.html#NoUnfolding"><span class="hs-identifier hs-var">NoUnfolding</span></a></span><span>      </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Maybe CoreArg
forall a. Maybe a
</span><a href="../../base/src/GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span>
</span><span id="line-1310"></span><span>        </span><span class="annot"><span class="annottext">Unfolding
</span><a href="GHC.Core.html#BootUnfolding"><span class="hs-identifier hs-var">BootUnfolding</span></a></span><span>    </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Maybe CoreArg
forall a. Maybe a
</span><a href="../../base/src/GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span>
</span><span id="line-1311"></span><span>        </span><span class="annot"><a href="GHC.Core.html#OtherCon"><span class="hs-identifier hs-type">OtherCon</span></a></span><span> </span><span class="hs-special">{</span><span class="hs-special">}</span><span>      </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Maybe CoreArg
forall a. Maybe a
</span><a href="../../base/src/GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span>
</span><span id="line-1312"></span><span>        </span><span class="annot"><a href="GHC.Core.html#DFunUnfolding"><span class="hs-identifier hs-type">DFunUnfolding</span></a></span><span> </span><span class="hs-special">{</span><span class="hs-special">}</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Maybe CoreArg
forall a. Maybe a
</span><a href="../../base/src/GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span>     </span><span class="hs-comment">-- Never unfold a DFun</span><span>
</span><span id="line-1313"></span><span>
</span><span id="line-1314"></span><span class="hs-comment">-- | Report the inlining of an identifier's RHS to the user, if requested.</span><span>
</span><span id="line-1315"></span><span id="local-6989586621680864124"><span class="annot"><a href="GHC.Core.Unfold.html#traceInline"><span class="hs-identifier hs-type">traceInline</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Driver.Session.html#DynFlags"><span class="hs-identifier hs-type">DynFlags</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Types.Var.html#Id"><span class="hs-identifier hs-type">Id</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../base/src/GHC.Base.html#String"><span class="hs-identifier hs-type">String</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Utils.Outputable.html#SDoc"><span class="hs-identifier hs-type">SDoc</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="#local-6989586621680864124"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="#local-6989586621680864124"><span class="hs-identifier hs-type">a</span></a></span></span><span>
</span><span id="line-1316"></span><span id="traceInline"><span class="annot"><span class="annottext">traceInline :: forall a. DynFlags -&gt; Id -&gt; String -&gt; SDoc -&gt; a -&gt; a
</span><a href="GHC.Core.Unfold.html#traceInline"><span class="hs-identifier hs-var hs-var">traceInline</span></a></span></span><span> </span><span id="local-6989586621680863467"><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680863467"><span class="hs-identifier hs-var">dflags</span></a></span></span><span> </span><span id="local-6989586621680863466"><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680863466"><span class="hs-identifier hs-var">inline_id</span></a></span></span><span> </span><span id="local-6989586621680863465"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621680863465"><span class="hs-identifier hs-var">str</span></a></span></span><span> </span><span id="local-6989586621680863464"><span class="annot"><span class="annottext">SDoc
</span><a href="#local-6989586621680863464"><span class="hs-identifier hs-var">doc</span></a></span></span><span> </span><span id="local-6989586621680863463"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621680863463"><span class="hs-identifier hs-var">result</span></a></span></span><span>
</span><span id="line-1317"></span><span>  </span><span class="hs-comment">-- We take care to ensure that doc is used in only one branch, ensuring that</span><span>
</span><span id="line-1318"></span><span>  </span><span class="hs-comment">-- the simplifier can push its allocation into the branch. See Note [INLINE</span><span>
</span><span id="line-1319"></span><span>  </span><span class="hs-comment">-- conditional tracing utilities].</span><span>
</span><span id="line-1320"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621680863462"><span class="hs-identifier hs-var">enable</span></a></span><span>    </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">DynFlags -&gt; String -&gt; SDoc -&gt; a -&gt; a
TraceAction
</span><a href="GHC.Utils.Error.html#traceAction"><span class="hs-identifier hs-var">traceAction</span></a></span><span> </span><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680863467"><span class="hs-identifier hs-var">dflags</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621680863465"><span class="hs-identifier hs-var">str</span></a></span><span> </span><span class="annot"><span class="annottext">SDoc
</span><a href="#local-6989586621680863464"><span class="hs-identifier hs-var">doc</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621680863463"><span class="hs-identifier hs-var">result</span></a></span><span>
</span><span id="line-1321"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621680863463"><span class="hs-identifier hs-var">result</span></a></span><span>
</span><span id="line-1322"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-1323"></span><span>    </span><span id="local-6989586621680863462"><span class="annot"><span class="annottext">enable :: Bool
</span><a href="#local-6989586621680863462"><span class="hs-identifier hs-var hs-var">enable</span></a></span></span><span>
</span><span id="line-1324"></span><span>      </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">DumpFlag -&gt; DynFlags -&gt; Bool
</span><a href="GHC.Driver.Session.html#dopt"><span class="hs-identifier hs-var">dopt</span></a></span><span> </span><span class="annot"><span class="annottext">DumpFlag
</span><a href="GHC.Driver.Flags.html#Opt_D_dump_verbose_inlinings"><span class="hs-identifier hs-var">Opt_D_dump_verbose_inlinings</span></a></span><span> </span><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680863467"><span class="hs-identifier hs-var">dflags</span></a></span><span>
</span><span id="line-1325"></span><span>      </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">True</span></span><span>
</span><span id="line-1326"></span><span>      </span><span class="hs-glyph">|</span><span> </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span id="local-6989586621680863454"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621680863454"><span class="hs-identifier hs-var">prefix</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">DynFlags -&gt; Maybe String
</span><a href="GHC.Driver.Session.html#inlineCheck"><span class="hs-identifier hs-var hs-var">inlineCheck</span></a></span><span> </span><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680863467"><span class="hs-identifier hs-var">dflags</span></a></span><span>
</span><span id="line-1327"></span><span>      </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621680863454"><span class="hs-identifier hs-var">prefix</span></a></span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; Bool
forall a. Eq a =&gt; [a] -&gt; [a] -&gt; Bool
</span><a href="../../base/src/Data.OldList.html#isPrefixOf"><span class="hs-operator hs-var">`isPrefixOf`</span></a></span><span> </span><span class="annot"><span class="annottext">OccName -&gt; String
</span><a href="GHC.Types.Name.Occurrence.html#occNameString"><span class="hs-identifier hs-var">occNameString</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Id -&gt; OccName
forall a. NamedThing a =&gt; a -&gt; OccName
</span><a href="GHC.Types.Name.html#getOccName"><span class="hs-identifier hs-var">getOccName</span></a></span><span> </span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680863466"><span class="hs-identifier hs-var">inline_id</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1328"></span><span>      </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span>
</span><span id="line-1329"></span><span>      </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">False</span></span><span>
</span><span id="line-1330"></span><span class="hs-pragma">{-# INLINE</span><span> </span><span class="annot"><a href="GHC.Core.Unfold.html#traceInline"><span class="hs-pragma hs-type">traceInline</span></a></span><span> </span><span class="hs-pragma">#-}</span><span> </span><span class="hs-comment">-- see Note [INLINE conditional tracing utilities]</span><span>
</span><span id="line-1331"></span><span>
</span><span id="line-1332"></span><span class="annot"><a href="GHC.Core.Unfold.html#tryUnfolding"><span class="hs-identifier hs-type">tryUnfolding</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Driver.Session.html#DynFlags"><span class="hs-identifier hs-type">DynFlags</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Types.Var.html#Id"><span class="hs-identifier hs-type">Id</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Bool</span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.Unfold.html#ArgSummary"><span class="hs-identifier hs-type">ArgSummary</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.Unfold.html#CallCtxt"><span class="hs-identifier hs-type">CallCtxt</span></a></span><span>
</span><span id="line-1333"></span><span>             </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.html#CoreExpr"><span class="hs-identifier hs-type">CoreExpr</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Bool</span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Bool</span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.html#UnfoldingGuidance"><span class="hs-identifier hs-type">UnfoldingGuidance</span></a></span><span>
</span><span id="line-1334"></span><span>             </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Maybe"><span class="hs-identifier hs-type">Maybe</span></a></span><span> </span><span class="annot"><a href="GHC.Core.html#CoreExpr"><span class="hs-identifier hs-type">CoreExpr</span></a></span><span>
</span><span id="line-1335"></span><span id="tryUnfolding"><span class="annot"><span class="annottext">tryUnfolding :: DynFlags
-&gt; Id
-&gt; Bool
-&gt; [ArgSummary]
-&gt; CallCtxt
-&gt; CoreArg
-&gt; Bool
-&gt; Bool
-&gt; UnfoldingGuidance
-&gt; Maybe CoreArg
</span><a href="GHC.Core.Unfold.html#tryUnfolding"><span class="hs-identifier hs-var hs-var">tryUnfolding</span></a></span></span><span> </span><span id="local-6989586621680863449"><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680863449"><span class="hs-identifier hs-var">dflags</span></a></span></span><span> </span><span id="local-6989586621680863448"><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680863448"><span class="hs-identifier hs-var">id</span></a></span></span><span> </span><span id="local-6989586621680863447"><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621680863447"><span class="hs-identifier hs-var">lone_variable</span></a></span></span><span>
</span><span id="line-1336"></span><span>             </span><span id="local-6989586621680863446"><span class="annot"><span class="annottext">[ArgSummary]
</span><a href="#local-6989586621680863446"><span class="hs-identifier hs-var">arg_infos</span></a></span></span><span> </span><span id="local-6989586621680863445"><span class="annot"><span class="annottext">CallCtxt
</span><a href="#local-6989586621680863445"><span class="hs-identifier hs-var">cont_info</span></a></span></span><span> </span><span id="local-6989586621680863444"><span class="annot"><span class="annottext">CoreArg
</span><a href="#local-6989586621680863444"><span class="hs-identifier hs-var">unf_template</span></a></span></span><span>
</span><span id="line-1337"></span><span>             </span><span id="local-6989586621680863443"><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621680863443"><span class="hs-identifier hs-var">is_wf</span></a></span></span><span> </span><span id="local-6989586621680863442"><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621680863442"><span class="hs-identifier hs-var">is_exp</span></a></span></span><span> </span><span id="local-6989586621680863441"><span class="annot"><span class="annottext">UnfoldingGuidance
</span><a href="#local-6989586621680863441"><span class="hs-identifier hs-var">guidance</span></a></span></span><span>
</span><span id="line-1338"></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">UnfoldingGuidance
</span><a href="#local-6989586621680863441"><span class="hs-identifier hs-var">guidance</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-1339"></span><span>     </span><span class="annot"><span class="annottext">UnfoldingGuidance
</span><a href="GHC.Core.html#UnfNever"><span class="hs-identifier hs-var">UnfNever</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">DynFlags -&gt; Id -&gt; String -&gt; SDoc -&gt; Maybe CoreArg -&gt; Maybe CoreArg
forall a. DynFlags -&gt; Id -&gt; String -&gt; SDoc -&gt; a -&gt; a
</span><a href="GHC.Core.Unfold.html#traceInline"><span class="hs-identifier hs-var">traceInline</span></a></span><span> </span><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680863449"><span class="hs-identifier hs-var">dflags</span></a></span><span> </span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680863448"><span class="hs-identifier hs-var">id</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621680863440"><span class="hs-identifier hs-var">str</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;UnfNever&quot;</span></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Maybe CoreArg
forall a. Maybe a
</span><a href="../../base/src/GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span>
</span><span id="line-1340"></span><span>
</span><span id="line-1341"></span><span>     </span><span class="annot"><a href="GHC.Core.html#UnfWhen"><span class="hs-identifier hs-type">UnfWhen</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">ug_arity :: UnfoldingGuidance -&gt; Int
</span><a href="GHC.Core.html#ug_arity"><span class="hs-identifier hs-var">ug_arity</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680863439"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863439"><span class="hs-identifier hs-var">uf_arity</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">ug_unsat_ok :: UnfoldingGuidance -&gt; Bool
</span><a href="GHC.Core.html#ug_unsat_ok"><span class="hs-identifier hs-var">ug_unsat_ok</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680863438"><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621680863438"><span class="hs-identifier hs-var">unsat_ok</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">ug_boring_ok :: UnfoldingGuidance -&gt; Bool
</span><a href="GHC.Core.html#ug_boring_ok"><span class="hs-identifier hs-var">ug_boring_ok</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680863437"><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621680863437"><span class="hs-identifier hs-var">boring_ok</span></a></span></span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-1342"></span><span>        </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621680863436"><span class="hs-identifier hs-var">enough_args</span></a></span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Bool -&gt; Bool
</span><span class="hs-operator hs-var">&amp;&amp;</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621680863437"><span class="hs-identifier hs-var">boring_ok</span></a></span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Bool -&gt; Bool
</span><span class="hs-operator hs-var">||</span></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621680863435"><span class="hs-identifier hs-var">some_benefit</span></a></span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Bool -&gt; Bool
</span><span class="hs-operator hs-var">||</span></span><span> </span><span class="annot"><span class="annottext">DynFlags -&gt; Bool
</span><a href="GHC.Driver.Session.html#ufVeryAggressive"><span class="hs-identifier hs-var hs-var">ufVeryAggressive</span></a></span><span> </span><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680863449"><span class="hs-identifier hs-var">dflags</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1343"></span><span>                </span><span class="hs-comment">-- See Note [INLINE for small functions (3)]</span><span>
</span><span id="line-1344"></span><span>        </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">DynFlags -&gt; Id -&gt; String -&gt; SDoc -&gt; Maybe CoreArg -&gt; Maybe CoreArg
forall a. DynFlags -&gt; Id -&gt; String -&gt; SDoc -&gt; a -&gt; a
</span><a href="GHC.Core.Unfold.html#traceInline"><span class="hs-identifier hs-var">traceInline</span></a></span><span> </span><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680863449"><span class="hs-identifier hs-var">dflags</span></a></span><span> </span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680863448"><span class="hs-identifier hs-var">id</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621680863440"><span class="hs-identifier hs-var">str</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Bool -&gt; SDoc -&gt; Bool -&gt; SDoc
forall {a}. Outputable a =&gt; a -&gt; SDoc -&gt; Bool -&gt; SDoc
</span><a href="#local-6989586621680863433"><span class="hs-identifier hs-var">mk_doc</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621680863435"><span class="hs-identifier hs-var">some_benefit</span></a></span><span> </span><span class="annot"><span class="annottext">SDoc
</span><a href="GHC.Utils.Outputable.html#empty"><span class="hs-identifier hs-var">empty</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">True</span></span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">CoreArg -&gt; Maybe CoreArg
forall a. a -&gt; Maybe a
</span><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-var">Just</span></a></span><span> </span><span class="annot"><span class="annottext">CoreArg
</span><a href="#local-6989586621680863444"><span class="hs-identifier hs-var">unf_template</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1345"></span><span>        </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span>
</span><span id="line-1346"></span><span>        </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">DynFlags -&gt; Id -&gt; String -&gt; SDoc -&gt; Maybe CoreArg -&gt; Maybe CoreArg
forall a. DynFlags -&gt; Id -&gt; String -&gt; SDoc -&gt; a -&gt; a
</span><a href="GHC.Core.Unfold.html#traceInline"><span class="hs-identifier hs-var">traceInline</span></a></span><span> </span><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680863449"><span class="hs-identifier hs-var">dflags</span></a></span><span> </span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680863448"><span class="hs-identifier hs-var">id</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621680863440"><span class="hs-identifier hs-var">str</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Bool -&gt; SDoc -&gt; Bool -&gt; SDoc
forall {a}. Outputable a =&gt; a -&gt; SDoc -&gt; Bool -&gt; SDoc
</span><a href="#local-6989586621680863433"><span class="hs-identifier hs-var">mk_doc</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621680863435"><span class="hs-identifier hs-var">some_benefit</span></a></span><span> </span><span class="annot"><span class="annottext">SDoc
</span><a href="GHC.Utils.Outputable.html#empty"><span class="hs-identifier hs-var">empty</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">False</span></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Maybe CoreArg
forall a. Maybe a
</span><a href="../../base/src/GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span>
</span><span id="line-1347"></span><span>        </span><span class="hs-keyword">where</span><span>
</span><span id="line-1348"></span><span>          </span><span id="local-6989586621680863435"><span class="annot"><span class="annottext">some_benefit :: Bool
</span><a href="#local-6989586621680863435"><span class="hs-identifier hs-var hs-var">some_benefit</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int -&gt; Bool
</span><a href="#local-6989586621680863431"><span class="hs-identifier hs-var">calc_some_benefit</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863439"><span class="hs-identifier hs-var">uf_arity</span></a></span><span>
</span><span id="line-1349"></span><span>          </span><span id="local-6989586621680863436"><span class="annot"><span class="annottext">enough_args :: Bool
</span><a href="#local-6989586621680863436"><span class="hs-identifier hs-var hs-var">enough_args</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863427"><span class="hs-identifier hs-var">n_val_args</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Bool
forall a. Ord a =&gt; a -&gt; a -&gt; Bool
</span><span class="hs-operator hs-var">&gt;=</span></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863439"><span class="hs-identifier hs-var">uf_arity</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Bool -&gt; Bool
</span><span class="hs-operator hs-var">||</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621680863438"><span class="hs-identifier hs-var">unsat_ok</span></a></span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Bool -&gt; Bool
</span><span class="hs-operator hs-var">&amp;&amp;</span></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863427"><span class="hs-identifier hs-var">n_val_args</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Bool
forall a. Ord a =&gt; a -&gt; a -&gt; Bool
</span><span class="hs-operator hs-var">&gt;</span></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">0</span></span><span class="hs-special">)</span><span>
</span><span id="line-1350"></span><span>
</span><span id="line-1351"></span><span>     </span><span class="annot"><a href="GHC.Core.html#UnfIfGoodArgs"><span class="hs-identifier hs-type">UnfIfGoodArgs</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">ug_args :: UnfoldingGuidance -&gt; [Int]
</span><a href="GHC.Core.html#ug_args"><span class="hs-identifier hs-var">ug_args</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680863426"><span class="annot"><span class="annottext">[Int]
</span><a href="#local-6989586621680863426"><span class="hs-identifier hs-var">arg_discounts</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">ug_res :: UnfoldingGuidance -&gt; Int
</span><a href="GHC.Core.html#ug_res"><span class="hs-identifier hs-var">ug_res</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680863425"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863425"><span class="hs-identifier hs-var">res_discount</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">ug_size :: UnfoldingGuidance -&gt; Int
</span><a href="GHC.Core.html#ug_size"><span class="hs-identifier hs-var">ug_size</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680863424"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863424"><span class="hs-identifier hs-var">size</span></a></span></span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-1352"></span><span>        </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">DynFlags -&gt; Bool
</span><a href="GHC.Driver.Session.html#ufVeryAggressive"><span class="hs-identifier hs-var hs-var">ufVeryAggressive</span></a></span><span> </span><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680863449"><span class="hs-identifier hs-var">dflags</span></a></span><span>
</span><span id="line-1353"></span><span>        </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">DynFlags -&gt; Id -&gt; String -&gt; SDoc -&gt; Maybe CoreArg -&gt; Maybe CoreArg
forall a. DynFlags -&gt; Id -&gt; String -&gt; SDoc -&gt; a -&gt; a
</span><a href="GHC.Core.Unfold.html#traceInline"><span class="hs-identifier hs-var">traceInline</span></a></span><span> </span><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680863449"><span class="hs-identifier hs-var">dflags</span></a></span><span> </span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680863448"><span class="hs-identifier hs-var">id</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621680863440"><span class="hs-identifier hs-var">str</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Bool -&gt; SDoc -&gt; Bool -&gt; SDoc
forall {a}. Outputable a =&gt; a -&gt; SDoc -&gt; Bool -&gt; SDoc
</span><a href="#local-6989586621680863433"><span class="hs-identifier hs-var">mk_doc</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621680863423"><span class="hs-identifier hs-var">some_benefit</span></a></span><span> </span><span class="annot"><span class="annottext">SDoc
</span><a href="#local-6989586621680863422"><span class="hs-identifier hs-var">extra_doc</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">True</span></span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">CoreArg -&gt; Maybe CoreArg
forall a. a -&gt; Maybe a
</span><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-var">Just</span></a></span><span> </span><span class="annot"><span class="annottext">CoreArg
</span><a href="#local-6989586621680863444"><span class="hs-identifier hs-var">unf_template</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1354"></span><span>        </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621680863443"><span class="hs-identifier hs-var">is_wf</span></a></span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Bool -&gt; Bool
</span><span class="hs-operator hs-var">&amp;&amp;</span></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621680863423"><span class="hs-identifier hs-var">some_benefit</span></a></span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Bool -&gt; Bool
</span><span class="hs-operator hs-var">&amp;&amp;</span></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621680863421"><span class="hs-identifier hs-var">small_enough</span></a></span><span>
</span><span id="line-1355"></span><span>        </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">DynFlags -&gt; Id -&gt; String -&gt; SDoc -&gt; Maybe CoreArg -&gt; Maybe CoreArg
forall a. DynFlags -&gt; Id -&gt; String -&gt; SDoc -&gt; a -&gt; a
</span><a href="GHC.Core.Unfold.html#traceInline"><span class="hs-identifier hs-var">traceInline</span></a></span><span> </span><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680863449"><span class="hs-identifier hs-var">dflags</span></a></span><span> </span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680863448"><span class="hs-identifier hs-var">id</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621680863440"><span class="hs-identifier hs-var">str</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Bool -&gt; SDoc -&gt; Bool -&gt; SDoc
forall {a}. Outputable a =&gt; a -&gt; SDoc -&gt; Bool -&gt; SDoc
</span><a href="#local-6989586621680863433"><span class="hs-identifier hs-var">mk_doc</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621680863423"><span class="hs-identifier hs-var">some_benefit</span></a></span><span> </span><span class="annot"><span class="annottext">SDoc
</span><a href="#local-6989586621680863422"><span class="hs-identifier hs-var">extra_doc</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">True</span></span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">CoreArg -&gt; Maybe CoreArg
forall a. a -&gt; Maybe a
</span><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-var">Just</span></a></span><span> </span><span class="annot"><span class="annottext">CoreArg
</span><a href="#local-6989586621680863444"><span class="hs-identifier hs-var">unf_template</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1356"></span><span>        </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span>
</span><span id="line-1357"></span><span>        </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">DynFlags -&gt; Id -&gt; String -&gt; SDoc -&gt; Maybe CoreArg -&gt; Maybe CoreArg
forall a. DynFlags -&gt; Id -&gt; String -&gt; SDoc -&gt; a -&gt; a
</span><a href="GHC.Core.Unfold.html#traceInline"><span class="hs-identifier hs-var">traceInline</span></a></span><span> </span><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680863449"><span class="hs-identifier hs-var">dflags</span></a></span><span> </span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680863448"><span class="hs-identifier hs-var">id</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621680863440"><span class="hs-identifier hs-var">str</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Bool -&gt; SDoc -&gt; Bool -&gt; SDoc
forall {a}. Outputable a =&gt; a -&gt; SDoc -&gt; Bool -&gt; SDoc
</span><a href="#local-6989586621680863433"><span class="hs-identifier hs-var">mk_doc</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621680863423"><span class="hs-identifier hs-var">some_benefit</span></a></span><span> </span><span class="annot"><span class="annottext">SDoc
</span><a href="#local-6989586621680863422"><span class="hs-identifier hs-var">extra_doc</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">False</span></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Maybe CoreArg
forall a. Maybe a
</span><a href="../../base/src/GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span>
</span><span id="line-1358"></span><span>        </span><span class="hs-keyword">where</span><span>
</span><span id="line-1359"></span><span>          </span><span id="local-6989586621680863423"><span class="annot"><span class="annottext">some_benefit :: Bool
</span><a href="#local-6989586621680863423"><span class="hs-identifier hs-var hs-var">some_benefit</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int -&gt; Bool
</span><a href="#local-6989586621680863431"><span class="hs-identifier hs-var">calc_some_benefit</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">[Int] -&gt; Int
forall (t :: * -&gt; *) a. Foldable t =&gt; t a -&gt; Int
</span><a href="../../base/src/Data.Foldable.html#length"><span class="hs-identifier hs-var">length</span></a></span><span> </span><span class="annot"><span class="annottext">[Int]
</span><a href="#local-6989586621680863426"><span class="hs-identifier hs-var">arg_discounts</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1360"></span><span>          </span><span id="local-6989586621680863422"><span class="annot"><span class="annottext">extra_doc :: SDoc
</span><a href="#local-6989586621680863422"><span class="hs-identifier hs-var hs-var">extra_doc</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;discounted size =&quot;</span></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#int"><span class="hs-identifier hs-var">int</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863419"><span class="hs-identifier hs-var">discounted_size</span></a></span><span>
</span><span id="line-1361"></span><span>          </span><span id="local-6989586621680863419"><span class="annot"><span class="annottext">discounted_size :: Int
</span><a href="#local-6989586621680863419"><span class="hs-identifier hs-var hs-var">discounted_size</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863424"><span class="hs-identifier hs-var">size</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="../../base/src/GHC.Num.html#-"><span class="hs-glyph hs-var">-</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863417"><span class="hs-identifier hs-var">discount</span></a></span><span>
</span><span id="line-1362"></span><span>          </span><span id="local-6989586621680863421"><span class="annot"><span class="annottext">small_enough :: Bool
</span><a href="#local-6989586621680863421"><span class="hs-identifier hs-var hs-var">small_enough</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863419"><span class="hs-identifier hs-var">discounted_size</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Bool
forall a. Ord a =&gt; a -&gt; a -&gt; Bool
</span><span class="hs-operator hs-var">&lt;=</span></span><span> </span><span class="annot"><span class="annottext">DynFlags -&gt; Int
</span><a href="GHC.Driver.Session.html#ufUseThreshold"><span class="hs-identifier hs-var hs-var">ufUseThreshold</span></a></span><span> </span><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680863449"><span class="hs-identifier hs-var">dflags</span></a></span><span>
</span><span id="line-1363"></span><span>          </span><span id="local-6989586621680863417"><span class="annot"><span class="annottext">discount :: Int
</span><a href="#local-6989586621680863417"><span class="hs-identifier hs-var hs-var">discount</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[Int] -&gt; Int -&gt; [ArgSummary] -&gt; CallCtxt -&gt; Int
</span><a href="GHC.Core.Unfold.html#computeDiscount"><span class="hs-identifier hs-var">computeDiscount</span></a></span><span> </span><span class="annot"><span class="annottext">[Int]
</span><a href="#local-6989586621680863426"><span class="hs-identifier hs-var">arg_discounts</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863425"><span class="hs-identifier hs-var">res_discount</span></a></span><span> </span><span class="annot"><span class="annottext">[ArgSummary]
</span><a href="#local-6989586621680863446"><span class="hs-identifier hs-var">arg_infos</span></a></span><span> </span><span class="annot"><span class="annottext">CallCtxt
</span><a href="#local-6989586621680863445"><span class="hs-identifier hs-var">cont_info</span></a></span><span>
</span><span id="line-1364"></span><span>
</span><span id="line-1365"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-1366"></span><span>    </span><span id="local-6989586621680863433"><span class="annot"><span class="annottext">mk_doc :: a -&gt; SDoc -&gt; Bool -&gt; SDoc
</span><a href="#local-6989586621680863433"><span class="hs-identifier hs-var hs-var">mk_doc</span></a></span></span><span> </span><span id="local-6989586621680863405"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621680863405"><span class="hs-identifier hs-var">some_benefit</span></a></span></span><span> </span><span id="local-6989586621680863404"><span class="annot"><span class="annottext">SDoc
</span><a href="#local-6989586621680863404"><span class="hs-identifier hs-var">extra_doc</span></a></span></span><span> </span><span id="local-6989586621680863403"><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621680863403"><span class="hs-identifier hs-var">yes_or_no</span></a></span></span><span>
</span><span id="line-1367"></span><span>      </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[SDoc] -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#vcat"><span class="hs-identifier hs-var">vcat</span></a></span><span> </span><span class="hs-special">[</span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;arg infos&quot;</span></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">[ArgSummary] -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">[ArgSummary]
</span><a href="#local-6989586621680863446"><span class="hs-identifier hs-var">arg_infos</span></a></span><span>
</span><span id="line-1368"></span><span>             </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;interesting continuation&quot;</span></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">CallCtxt -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">CallCtxt
</span><a href="#local-6989586621680863445"><span class="hs-identifier hs-var">cont_info</span></a></span><span>
</span><span id="line-1369"></span><span>             </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;some_benefit&quot;</span></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">a -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621680863405"><span class="hs-identifier hs-var">some_benefit</span></a></span><span>
</span><span id="line-1370"></span><span>             </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;is exp:&quot;</span></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">Bool -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621680863442"><span class="hs-identifier hs-var">is_exp</span></a></span><span>
</span><span id="line-1371"></span><span>             </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;is work-free:&quot;</span></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">Bool -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621680863443"><span class="hs-identifier hs-var">is_wf</span></a></span><span>
</span><span id="line-1372"></span><span>             </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;guidance&quot;</span></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">UnfoldingGuidance -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">UnfoldingGuidance
</span><a href="#local-6989586621680863441"><span class="hs-identifier hs-var">guidance</span></a></span><span>
</span><span id="line-1373"></span><span>             </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">SDoc
</span><a href="#local-6989586621680863404"><span class="hs-identifier hs-var">extra_doc</span></a></span><span>
</span><span id="line-1374"></span><span>             </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;ANSWER =&quot;</span></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span> </span><span class="hs-keyword">if</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621680863403"><span class="hs-identifier hs-var">yes_or_no</span></a></span><span> </span><span class="hs-keyword">then</span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;YES&quot;</span></span><span> </span><span class="hs-keyword">else</span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;NO&quot;</span></span><span class="hs-special">]</span><span>
</span><span id="line-1375"></span><span>
</span><span id="line-1376"></span><span>    </span><span id="local-6989586621680863440"><span class="annot"><span class="annottext">str :: String
</span><a href="#local-6989586621680863440"><span class="hs-identifier hs-var hs-var">str</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;Considering inlining: &quot;</span></span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; String
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="../../base/src/GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">DynFlags -&gt; SDoc -&gt; String
</span><a href="GHC.Utils.Outputable.html#showSDocDump"><span class="hs-identifier hs-var">showSDocDump</span></a></span><span> </span><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680863449"><span class="hs-identifier hs-var">dflags</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Id -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680863448"><span class="hs-identifier hs-var">id</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1377"></span><span>    </span><span id="local-6989586621680863427"><span class="annot"><span class="annottext">n_val_args :: Int
</span><a href="#local-6989586621680863427"><span class="hs-identifier hs-var hs-var">n_val_args</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[ArgSummary] -&gt; Int
forall (t :: * -&gt; *) a. Foldable t =&gt; t a -&gt; Int
</span><a href="../../base/src/Data.Foldable.html#length"><span class="hs-identifier hs-var">length</span></a></span><span> </span><span class="annot"><span class="annottext">[ArgSummary]
</span><a href="#local-6989586621680863446"><span class="hs-identifier hs-var">arg_infos</span></a></span><span>
</span><span id="line-1378"></span><span>
</span><span id="line-1379"></span><span>           </span><span class="hs-comment">-- some_benefit is used when the RHS is small enough</span><span>
</span><span id="line-1380"></span><span>           </span><span class="hs-comment">-- and the call has enough (or too many) value</span><span>
</span><span id="line-1381"></span><span>           </span><span class="hs-comment">-- arguments (ie n_val_args &gt;= arity). But there must</span><span>
</span><span id="line-1382"></span><span>           </span><span class="hs-comment">-- be *something* interesting about some argument, or the</span><span>
</span><span id="line-1383"></span><span>           </span><span class="hs-comment">-- result context, to make it worth inlining</span><span>
</span><span id="line-1384"></span><span>    </span><span class="annot"><a href="#local-6989586621680863431"><span class="hs-identifier hs-type">calc_some_benefit</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Types.Basic.html#Arity"><span class="hs-identifier hs-type">Arity</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Bool</span></span><span>   </span><span class="hs-comment">-- The Arity is the number of args</span><span>
</span><span id="line-1385"></span><span>                                         </span><span class="hs-comment">-- expected by the unfolding</span><span>
</span><span id="line-1386"></span><span>    </span><span id="local-6989586621680863431"><span class="annot"><span class="annottext">calc_some_benefit :: Int -&gt; Bool
</span><a href="#local-6989586621680863431"><span class="hs-identifier hs-var hs-var">calc_some_benefit</span></a></span></span><span> </span><span id="local-6989586621680863398"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863398"><span class="hs-identifier hs-var">uf_arity</span></a></span></span><span>
</span><span id="line-1387"></span><span>       </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Bool
</span><span class="hs-identifier hs-var">not</span></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621680863397"><span class="hs-identifier hs-var">saturated</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621680863396"><span class="hs-identifier hs-var">interesting_args</span></a></span><span>       </span><span class="hs-comment">-- Under-saturated</span><span>
</span><span id="line-1388"></span><span>                                        </span><span class="hs-comment">-- Note [Unsaturated applications]</span><span>
</span><span id="line-1389"></span><span>       </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621680863396"><span class="hs-identifier hs-var">interesting_args</span></a></span><span>   </span><span class="hs-comment">-- Saturated or over-saturated</span><span>
</span><span id="line-1390"></span><span>                  </span><span class="annot"><span class="annottext">Bool -&gt; Bool -&gt; Bool
</span><span class="hs-operator hs-var">||</span></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621680863395"><span class="hs-identifier hs-var">interesting_call</span></a></span><span>
</span><span id="line-1391"></span><span>      </span><span class="hs-keyword">where</span><span>
</span><span id="line-1392"></span><span>        </span><span id="local-6989586621680863397"><span class="annot"><span class="annottext">saturated :: Bool
</span><a href="#local-6989586621680863397"><span class="hs-identifier hs-var hs-var">saturated</span></a></span></span><span>      </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863427"><span class="hs-identifier hs-var">n_val_args</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Bool
forall a. Ord a =&gt; a -&gt; a -&gt; Bool
</span><span class="hs-operator hs-var">&gt;=</span></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863398"><span class="hs-identifier hs-var">uf_arity</span></a></span><span>
</span><span id="line-1393"></span><span>        </span><span id="local-6989586621680863392"><span class="annot"><span class="annottext">over_saturated :: Bool
</span><a href="#local-6989586621680863392"><span class="hs-identifier hs-var hs-var">over_saturated</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863427"><span class="hs-identifier hs-var">n_val_args</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Bool
forall a. Ord a =&gt; a -&gt; a -&gt; Bool
</span><span class="hs-operator hs-var">&gt;</span></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863398"><span class="hs-identifier hs-var">uf_arity</span></a></span><span>
</span><span id="line-1394"></span><span>        </span><span id="local-6989586621680863396"><span class="annot"><span class="annottext">interesting_args :: Bool
</span><a href="#local-6989586621680863396"><span class="hs-identifier hs-var hs-var">interesting_args</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(ArgSummary -&gt; Bool) -&gt; [ArgSummary] -&gt; Bool
forall (t :: * -&gt; *) a. Foldable t =&gt; (a -&gt; Bool) -&gt; t a -&gt; Bool
</span><a href="../../base/src/Data.Foldable.html#any"><span class="hs-identifier hs-var">any</span></a></span><span> </span><span class="annot"><span class="annottext">ArgSummary -&gt; Bool
</span><a href="GHC.Core.Unfold.html#nonTriv"><span class="hs-identifier hs-var">nonTriv</span></a></span><span> </span><span class="annot"><span class="annottext">[ArgSummary]
</span><a href="#local-6989586621680863446"><span class="hs-identifier hs-var">arg_infos</span></a></span><span>
</span><span id="line-1395"></span><span>                </span><span class="hs-comment">-- NB: (any nonTriv arg_infos) looks at the</span><span>
</span><span id="line-1396"></span><span>                </span><span class="hs-comment">-- over-saturated args too which is &quot;wrong&quot;;</span><span>
</span><span id="line-1397"></span><span>                </span><span class="hs-comment">-- but if over-saturated we inline anyway.</span><span>
</span><span id="line-1398"></span><span>
</span><span id="line-1399"></span><span>        </span><span id="local-6989586621680863395"><span class="annot"><span class="annottext">interesting_call :: Bool
</span><a href="#local-6989586621680863395"><span class="hs-identifier hs-var hs-var">interesting_call</span></a></span></span><span>
</span><span id="line-1400"></span><span>          </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621680863392"><span class="hs-identifier hs-var">over_saturated</span></a></span><span>
</span><span id="line-1401"></span><span>          </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">True</span></span><span>
</span><span id="line-1402"></span><span>          </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span>
</span><span id="line-1403"></span><span>          </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">CallCtxt
</span><a href="#local-6989586621680863445"><span class="hs-identifier hs-var">cont_info</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-1404"></span><span>              </span><span class="annot"><span class="annottext">CallCtxt
</span><a href="GHC.Core.Unfold.html#CaseCtxt"><span class="hs-identifier hs-var">CaseCtxt</span></a></span><span>   </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Bool
</span><span class="hs-identifier hs-var">not</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621680863447"><span class="hs-identifier hs-var">lone_variable</span></a></span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Bool -&gt; Bool
</span><span class="hs-operator hs-var">&amp;&amp;</span></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621680863442"><span class="hs-identifier hs-var">is_exp</span></a></span><span class="hs-special">)</span><span>  </span><span class="hs-comment">-- Note [Lone variables]</span><span>
</span><span id="line-1405"></span><span>              </span><span class="annot"><span class="annottext">CallCtxt
</span><a href="GHC.Core.Unfold.html#ValAppCtxt"><span class="hs-identifier hs-var">ValAppCtxt</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">True</span></span><span>                           </span><span class="hs-comment">-- Note [Cast then apply]</span><span>
</span><span id="line-1406"></span><span>              </span><span class="annot"><span class="annottext">CallCtxt
</span><a href="GHC.Core.Unfold.html#RuleArgCtxt"><span class="hs-identifier hs-var">RuleArgCtxt</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863398"><span class="hs-identifier hs-var">uf_arity</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Bool
forall a. Ord a =&gt; a -&gt; a -&gt; Bool
</span><span class="hs-operator hs-var">&gt;</span></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">0</span></span><span>  </span><span class="hs-comment">-- See Note [Unfold info lazy contexts]</span><span>
</span><span id="line-1407"></span><span>              </span><span class="annot"><span class="annottext">CallCtxt
</span><a href="GHC.Core.Unfold.html#DiscArgCtxt"><span class="hs-identifier hs-var">DiscArgCtxt</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863398"><span class="hs-identifier hs-var">uf_arity</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Bool
forall a. Ord a =&gt; a -&gt; a -&gt; Bool
</span><span class="hs-operator hs-var">&gt;</span></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">0</span></span><span>  </span><span class="hs-comment">-- Note [Inlining in ArgCtxt]</span><span>
</span><span id="line-1408"></span><span>              </span><span class="annot"><span class="annottext">CallCtxt
</span><a href="GHC.Core.Unfold.html#RhsCtxt"><span class="hs-identifier hs-var">RhsCtxt</span></a></span><span>     </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863398"><span class="hs-identifier hs-var">uf_arity</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Bool
forall a. Ord a =&gt; a -&gt; a -&gt; Bool
</span><span class="hs-operator hs-var">&gt;</span></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">0</span></span><span>  </span><span class="hs-comment">--</span><span>
</span><span id="line-1409"></span><span>              </span><span id="local-6989586621680863383"><span class="annot"><span class="annottext">CallCtxt
</span><a href="#local-6989586621680863383"><span class="hs-identifier hs-var">_other</span></a></span></span><span>      </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">False</span></span><span>         </span><span class="hs-comment">-- See Note [Nested functions]</span><span>
</span><span id="line-1410"></span><span>
</span><span id="line-1411"></span><span>
</span><span id="line-1412"></span><span class="hs-comment">{-
Note [Unfold into lazy contexts], Note [RHS of lets]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
When the call is the argument of a function with a RULE, or the RHS of a let,
we are a little bit keener to inline.  For example
     f y = (y,y,y)
     g y = let x = f y in ...(case x of (a,b,c) -&gt; ...) ...
We'd inline 'f' if the call was in a case context, and it kind-of-is,
only we can't see it.  Also
     x = f v
could be expensive whereas
     x = case v of (a,b) -&gt; a
is patently cheap and may allow more eta expansion.
So we treat the RHS of a let as not-totally-boring.

Note [Unsaturated applications]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
When a call is not saturated, we *still* inline if one of the
arguments has interesting structure.  That's sometimes very important.
A good example is the Ord instance for Bool in Base:

 Rec {
    $fOrdBool =GHC.Classes.D:Ord
                 @ Bool
                 ...
                 $cmin_ajX

    $cmin_ajX [Occ=LoopBreaker] :: Bool -&gt; Bool -&gt; Bool
    $cmin_ajX = GHC.Classes.$dmmin @ Bool $fOrdBool
  }

But the defn of GHC.Classes.$dmmin is:

  $dmmin :: forall a. GHC.Classes.Ord a =&gt; a -&gt; a -&gt; a
    {- Arity: 3, HasNoCafRefs, Strictness: SLL,
       Unfolding: (\ @ a $dOrd :: GHC.Classes.Ord a x :: a y :: a -&gt;
                   case @ a GHC.Classes.&lt;= @ a $dOrd x y of wild {
                     GHC.Types.False -&gt; y GHC.Types.True -&gt; x }) -}

We *really* want to inline $dmmin, even though it has arity 3, in
order to unravel the recursion.


Note [Things to watch]
~~~~~~~~~~~~~~~~~~~~~~
*   { y = I# 3; x = y `cast` co; ...case (x `cast` co) of ... }
    Assume x is exported, so not inlined unconditionally.
    Then we want x to inline unconditionally; no reason for it
    not to, and doing so avoids an indirection.

*   { x = I# 3; ....f x.... }
    Make sure that x does not inline unconditionally!
    Lest we get extra allocation.

Note [Inlining an InlineRule]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
An InlineRules is used for
  (a) programmer INLINE pragmas
  (b) inlinings from worker/wrapper

For (a) the RHS may be large, and our contract is that we *only* inline
when the function is applied to all the arguments on the LHS of the
source-code defn.  (The uf_arity in the rule.)

However for worker/wrapper it may be worth inlining even if the
arity is not satisfied (as we do in the CoreUnfolding case) so we don't
require saturation.

Note [Nested functions]
~~~~~~~~~~~~~~~~~~~~~~~
At one time we treated a call of a non-top-level function as
&quot;interesting&quot; (regardless of how boring the context) in the hope
that inlining it would eliminate the binding, and its allocation.
Specifically, in the default case of interesting_call we had
   _other -&gt; not is_top &amp;&amp; uf_arity &gt; 0

But actually postInlineUnconditionally does some of this and overall
it makes virtually no difference to nofib.  So I simplified away this
special case

Note [Cast then apply]
~~~~~~~~~~~~~~~~~~~~~~
Consider
   myIndex = __inline_me ( (/\a. &lt;blah&gt;) |&gt; co )
   co :: (forall a. a -&gt; a) ~ (forall a. T a)
     ... /\a.\x. case ((myIndex a) |&gt; sym co) x of { ... } ...

We need to inline myIndex to unravel this; but the actual call (myIndex a) has
no value arguments.  The ValAppCtxt gives it enough incentive to inline.

Note [Inlining in ArgCtxt]
~~~~~~~~~~~~~~~~~~~~~~~~~~
The condition (arity &gt; 0) here is very important, because otherwise
we end up inlining top-level stuff into useless places; eg
   x = I# 3#
   f = \y.  g x
This can make a very big difference: it adds 16% to nofib 'integer' allocs,
and 20% to 'power'.

At one stage I replaced this condition by 'True' (leading to the above
slow-down).  The motivation was test eyeball/inline1.hs; but that seems
to work ok now.

NOTE: arguably, we should inline in ArgCtxt only if the result of the
call is at least CONLIKE.  At least for the cases where we use ArgCtxt
for the RHS of a 'let', we only profit from the inlining if we get a
CONLIKE thing (modulo lets).

Note [Lone variables]   See also Note [Interaction of exprIsWorkFree and lone variables]
~~~~~~~~~~~~~~~~~~~~~   which appears below
The &quot;lone-variable&quot; case is important.  I spent ages messing about
with unsatisfactory variants, but this is nice.  The idea is that if a
variable appears all alone

        as an arg of lazy fn, or rhs    BoringCtxt
        as scrutinee of a case          CaseCtxt
        as arg of a fn                  ArgCtxt
AND
        it is bound to a cheap expression

then we should not inline it (unless there is some other reason,
e.g. it is the sole occurrence).  That is what is happening at
the use of 'lone_variable' in 'interesting_call'.

Why?  At least in the case-scrutinee situation, turning
        let x = (a,b) in case x of y -&gt; ...
into
        let x = (a,b) in case (a,b) of y -&gt; ...
and thence to
        let x = (a,b) in let y = (a,b) in ...
is bad if the binding for x will remain.

Another example: I discovered that strings
were getting inlined straight back into applications of 'error'
because the latter is strict.
        s = &quot;foo&quot;
        f = \x -&gt; ...(error s)...

Fundamentally such contexts should not encourage inlining because, provided
the RHS is &quot;expandable&quot; (see Note [exprIsExpandable] in GHC.Core.Utils) the
context can ``see'' the unfolding of the variable (e.g. case or a
RULE) so there's no gain.

However, watch out:

 * Consider this:
        foo = _inline_ (\n. [n])
        bar = _inline_ (foo 20)
        baz = \n. case bar of { (m:_) -&gt; m + n }
   Here we really want to inline 'bar' so that we can inline 'foo'
   and the whole thing unravels as it should obviously do.  This is
   important: in the NDP project, 'bar' generates a closure data
   structure rather than a list.

   So the non-inlining of lone_variables should only apply if the
   unfolding is regarded as cheap; because that is when exprIsConApp_maybe
   looks through the unfolding.  Hence the &quot;&amp;&amp; is_wf&quot; in the
   InlineRule branch.

 * Even a type application or coercion isn't a lone variable.
   Consider
        case $fMonadST @ RealWorld of { :DMonad a b c -&gt; c }
   We had better inline that sucker!  The case won't see through it.

   For now, I'm treating treating a variable applied to types
   in a *lazy* context &quot;lone&quot;. The motivating example was
        f = /\a. \x. BIG
        g = /\a. \y.  h (f a)
   There's no advantage in inlining f here, and perhaps
   a significant disadvantage.  Hence some_val_args in the Stop case

Note [Interaction of exprIsWorkFree and lone variables]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The lone-variable test says &quot;don't inline if a case expression
scrutinises a lone variable whose unfolding is cheap&quot;.  It's very
important that, under these circumstances, exprIsConApp_maybe
can spot a constructor application. So, for example, we don't
consider
        let x = e in (x,x)
to be cheap, and that's good because exprIsConApp_maybe doesn't
think that expression is a constructor application.

In the 'not (lone_variable &amp;&amp; is_wf)' test, I used to test is_value
rather than is_wf, which was utterly wrong, because the above
expression responds True to exprIsHNF, which is what sets is_value.

This kind of thing can occur if you have

        {-# INLINE foo #-}
        foo = let x = e in (x,x)

which Roman did.


-}</span><span>
</span><span id="line-1607"></span><span>
</span><span id="line-1608"></span><span class="annot"><a href="GHC.Core.Unfold.html#computeDiscount"><span class="hs-identifier hs-type">computeDiscount</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">[</span><span class="annot"><span class="hs-identifier hs-type">Int</span></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Int</span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.Unfold.html#ArgSummary"><span class="hs-identifier hs-type">ArgSummary</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.Unfold.html#CallCtxt"><span class="hs-identifier hs-type">CallCtxt</span></a></span><span>
</span><span id="line-1609"></span><span>                </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Int</span></span><span>
</span><span id="line-1610"></span><span id="computeDiscount"><span class="annot"><span class="annottext">computeDiscount :: [Int] -&gt; Int -&gt; [ArgSummary] -&gt; CallCtxt -&gt; Int
</span><a href="GHC.Core.Unfold.html#computeDiscount"><span class="hs-identifier hs-var hs-var">computeDiscount</span></a></span></span><span> </span><span id="local-6989586621680863382"><span class="annot"><span class="annottext">[Int]
</span><a href="#local-6989586621680863382"><span class="hs-identifier hs-var">arg_discounts</span></a></span></span><span> </span><span id="local-6989586621680863381"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863381"><span class="hs-identifier hs-var">res_discount</span></a></span></span><span> </span><span id="local-6989586621680863380"><span class="annot"><span class="annottext">[ArgSummary]
</span><a href="#local-6989586621680863380"><span class="hs-identifier hs-var">arg_infos</span></a></span></span><span> </span><span id="local-6989586621680863379"><span class="annot"><span class="annottext">CallCtxt
</span><a href="#local-6989586621680863379"><span class="hs-identifier hs-var">cont_info</span></a></span></span><span>
</span><span id="line-1611"></span><span>
</span><span id="line-1612"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">10</span></span><span>          </span><span class="hs-comment">-- Discount of 10 because the result replaces the call</span><span>
</span><span id="line-1613"></span><span>                </span><span class="hs-comment">-- so we count 10 for the function itself</span><span>
</span><span id="line-1614"></span><span>
</span><span id="line-1615"></span><span>    </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="../../base/src/GHC.Num.html#%2B"><span class="hs-operator hs-var">+</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">10</span></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="../../base/src/GHC.Num.html#%2A"><span class="hs-operator hs-var">*</span></a></span><span> </span><span class="annot"><span class="annottext">[Int] -&gt; Int
forall (t :: * -&gt; *) a. Foldable t =&gt; t a -&gt; Int
</span><a href="../../base/src/Data.Foldable.html#length"><span class="hs-identifier hs-var">length</span></a></span><span> </span><span class="annot"><span class="annottext">[Int]
</span><a href="#local-6989586621680863378"><span class="hs-identifier hs-var">actual_arg_discounts</span></a></span><span>
</span><span id="line-1616"></span><span>               </span><span class="hs-comment">-- Discount of 10 for each arg supplied,</span><span>
</span><span id="line-1617"></span><span>               </span><span class="hs-comment">-- because the result replaces the call</span><span>
</span><span id="line-1618"></span><span>
</span><span id="line-1619"></span><span>    </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="../../base/src/GHC.Num.html#%2B"><span class="hs-operator hs-var">+</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863377"><span class="hs-identifier hs-var">total_arg_discount</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="../../base/src/GHC.Num.html#%2B"><span class="hs-operator hs-var">+</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863376"><span class="hs-identifier hs-var">res_discount'</span></a></span><span>
</span><span id="line-1620"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-1621"></span><span>    </span><span id="local-6989586621680863378"><span class="annot"><span class="annottext">actual_arg_discounts :: [Int]
</span><a href="#local-6989586621680863378"><span class="hs-identifier hs-var hs-var">actual_arg_discounts</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(Int -&gt; ArgSummary -&gt; Int) -&gt; [Int] -&gt; [ArgSummary] -&gt; [Int]
forall a b c. (a -&gt; b -&gt; c) -&gt; [a] -&gt; [b] -&gt; [c]
</span><a href="../../base/src/GHC.List.html#zipWith"><span class="hs-identifier hs-var">zipWith</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; ArgSummary -&gt; Int
forall {p}. Num p =&gt; p -&gt; ArgSummary -&gt; p
</span><a href="#local-6989586621680863373"><span class="hs-identifier hs-var">mk_arg_discount</span></a></span><span> </span><span class="annot"><span class="annottext">[Int]
</span><a href="#local-6989586621680863382"><span class="hs-identifier hs-var">arg_discounts</span></a></span><span> </span><span class="annot"><span class="annottext">[ArgSummary]
</span><a href="#local-6989586621680863380"><span class="hs-identifier hs-var">arg_infos</span></a></span><span>
</span><span id="line-1622"></span><span>    </span><span id="local-6989586621680863377"><span class="annot"><span class="annottext">total_arg_discount :: Int
</span><a href="#local-6989586621680863377"><span class="hs-identifier hs-var hs-var">total_arg_discount</span></a></span></span><span>   </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[Int] -&gt; Int
forall (t :: * -&gt; *) a. (Foldable t, Num a) =&gt; t a -&gt; a
</span><a href="../../base/src/Data.Foldable.html#sum"><span class="hs-identifier hs-var">sum</span></a></span><span> </span><span class="annot"><span class="annottext">[Int]
</span><a href="#local-6989586621680863378"><span class="hs-identifier hs-var">actual_arg_discounts</span></a></span><span>
</span><span id="line-1623"></span><span>
</span><span id="line-1624"></span><span>    </span><span id="local-6989586621680863373"><span class="annot"><span class="annottext">mk_arg_discount :: p -&gt; ArgSummary -&gt; p
</span><a href="#local-6989586621680863373"><span class="hs-identifier hs-var hs-var">mk_arg_discount</span></a></span></span><span> </span><span class="annot"><span class="annottext">p
</span><span class="hs-identifier">_</span></span><span>        </span><span class="annot"><span class="annottext">ArgSummary
</span><a href="GHC.Core.Unfold.html#TrivArg"><span class="hs-identifier hs-var">TrivArg</span></a></span><span>    </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">p
</span><span class="hs-number">0</span></span><span>
</span><span id="line-1625"></span><span>    </span><span class="annot"><a href="#local-6989586621680863373"><span class="hs-identifier hs-var">mk_arg_discount</span></a></span><span> </span><span class="annot"><span class="annottext">p
</span><span class="hs-identifier">_</span></span><span>        </span><span class="annot"><span class="annottext">ArgSummary
</span><a href="GHC.Core.Unfold.html#NonTrivArg"><span class="hs-identifier hs-var">NonTrivArg</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">p
</span><span class="hs-number">10</span></span><span>
</span><span id="line-1626"></span><span>    </span><span class="annot"><a href="#local-6989586621680863373"><span class="hs-identifier hs-var">mk_arg_discount</span></a></span><span> </span><span id="local-6989586621680863367"><span class="annot"><span class="annottext">p
</span><a href="#local-6989586621680863367"><span class="hs-identifier hs-var">discount</span></a></span></span><span> </span><span class="annot"><span class="annottext">ArgSummary
</span><a href="GHC.Core.Unfold.html#ValueArg"><span class="hs-identifier hs-var">ValueArg</span></a></span><span>   </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">p
</span><a href="#local-6989586621680863367"><span class="hs-identifier hs-var">discount</span></a></span><span>
</span><span id="line-1627"></span><span>
</span><span id="line-1628"></span><span>    </span><span id="local-6989586621680863376"><span class="annot"><span class="annottext">res_discount' :: Int
</span><a href="#local-6989586621680863376"><span class="hs-identifier hs-var hs-var">res_discount'</span></a></span></span><span>
</span><span id="line-1629"></span><span>      </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Ordering
</span><span class="hs-identifier hs-var">LT</span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">[Int]
</span><a href="#local-6989586621680863382"><span class="hs-identifier hs-var">arg_discounts</span></a></span><span> </span><span class="annot"><span class="annottext">[Int] -&gt; [ArgSummary] -&gt; Ordering
forall a b. [a] -&gt; [b] -&gt; Ordering
</span><a href="GHC.Utils.Misc.html#compareLength"><span class="hs-operator hs-var">`compareLength`</span></a></span><span> </span><span class="annot"><span class="annottext">[ArgSummary]
</span><a href="#local-6989586621680863380"><span class="hs-identifier hs-var">arg_infos</span></a></span><span>
</span><span id="line-1630"></span><span>      </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863381"><span class="hs-identifier hs-var">res_discount</span></a></span><span>   </span><span class="hs-comment">-- Over-saturated</span><span>
</span><span id="line-1631"></span><span>      </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span>
</span><span id="line-1632"></span><span>      </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">CallCtxt
</span><a href="#local-6989586621680863379"><span class="hs-identifier hs-var">cont_info</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-1633"></span><span>           </span><span class="annot"><span class="annottext">CallCtxt
</span><a href="GHC.Core.Unfold.html#BoringCtxt"><span class="hs-identifier hs-var">BoringCtxt</span></a></span><span>  </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">0</span></span><span>
</span><span id="line-1634"></span><span>           </span><span class="annot"><span class="annottext">CallCtxt
</span><a href="GHC.Core.Unfold.html#CaseCtxt"><span class="hs-identifier hs-var">CaseCtxt</span></a></span><span>    </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863381"><span class="hs-identifier hs-var">res_discount</span></a></span><span>  </span><span class="hs-comment">-- Presumably a constructor</span><span>
</span><span id="line-1635"></span><span>           </span><span class="annot"><span class="annottext">CallCtxt
</span><a href="GHC.Core.Unfold.html#ValAppCtxt"><span class="hs-identifier hs-var">ValAppCtxt</span></a></span><span>  </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863381"><span class="hs-identifier hs-var">res_discount</span></a></span><span>  </span><span class="hs-comment">-- Presumably a function</span><span>
</span><span id="line-1636"></span><span>           </span><span class="annot"><span class="annottext">CallCtxt
</span><span class="hs-identifier">_</span></span><span>           </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">40</span></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Ord a =&gt; a -&gt; a -&gt; a
</span><span class="hs-operator hs-var">`min`</span></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680863381"><span class="hs-identifier hs-var">res_discount</span></a></span><span>
</span><span id="line-1637"></span><span>                </span><span class="hs-comment">-- ToDo: this 40 `min` res_discount doesn't seem right</span><span>
</span><span id="line-1638"></span><span>                </span><span class="hs-comment">--   for DiscArgCtxt it shouldn't matter because the function will</span><span>
</span><span id="line-1639"></span><span>                </span><span class="hs-comment">--       get the arg discount for any non-triv arg</span><span>
</span><span id="line-1640"></span><span>                </span><span class="hs-comment">--   for RuleArgCtxt we do want to be keener to inline; but not only</span><span>
</span><span id="line-1641"></span><span>                </span><span class="hs-comment">--       constructor results</span><span>
</span><span id="line-1642"></span><span>                </span><span class="hs-comment">--   for RhsCtxt I suppose that exposing a data con is good in general</span><span>
</span><span id="line-1643"></span><span>                </span><span class="hs-comment">--   And 40 seems very arbitrary</span><span>
</span><span id="line-1644"></span><span>                </span><span class="hs-comment">--</span><span>
</span><span id="line-1645"></span><span>                </span><span class="hs-comment">-- res_discount can be very large when a function returns</span><span>
</span><span id="line-1646"></span><span>                </span><span class="hs-comment">-- constructors; but we only want to invoke that large discount</span><span>
</span><span id="line-1647"></span><span>                </span><span class="hs-comment">-- when there's a case continuation.</span><span>
</span><span id="line-1648"></span><span>                </span><span class="hs-comment">-- Otherwise we, rather arbitrarily, threshold it.  Yuk.</span><span>
</span><span id="line-1649"></span><span>                </span><span class="hs-comment">-- But we want to avoid inlining large functions that return</span><span>
</span><span id="line-1650"></span><span>                </span><span class="hs-comment">-- constructors into contexts that are simply &quot;interesting&quot;</span><span>
</span><span id="line-1651"></span></pre></body></html>